Google Code Jam Round 1C 2015 Problem A. Brattleship

Problem

You're about to play a simplified "battleship" game with your little brother. The board for this game is a rectangular grid with R rows and C columns. At the start of the game, you will close your eyes, and you will keep them closed until the end of the game. Your little brother will take a single rectangular 1 x W ship and place it horizontally somewhere on the board. The ship must always fit entirely on the board, with each cell of the ship occupying exactly one of the grid's cells, and it can never be rotated.

In each turn of the game, you name a cell on the board, and your little brother tells you whether that is a hit (one of the cells occupied by the ship) or a miss. (Your little brother doesn't say which part of the ship was hit -- just that the cell you named has a part of the ship in it.) You have perfect memory, and can keep track of all the information he has given you. Once you have named all of the cells occupied by the ship, the game is over (the ship is sunk), and your score is the number of turns taken. Your goal is to minimize your score.

Although the ship is not supposed to be moved once it is placed, you know that your little brother, who is a brat, plans to cheat by changing the location of the ship whenever he wants, as long as the ship remains horizontal and completely on the board, and the new location is consistent with all the information he has given so far. For example, for a 1x4 board and 1x2 ship, your little brother could initially place the ship such that it overlaps the leftmost two columns. If your first guess was row 1, column 2, he could choose to secretly move the ship to the rightmost two columns, and tell you that (1, 2) was a miss. If your next guess after that was (1, 3), though, then he could not say that was also a miss and move the ship back to its original location, since that would be inconsistent with what he said about (1, 2) earlier.

Not only do you know that your little brother will cheat, he knows that you know. If you both play optimally (you to minimize your score, him to maximize it), what is the lowest score that you can guarantee you will achieve, regardless of what your little brother does?

A:

 有r*c的一个矩阵,现在有一个1*w的条状物放在矩阵内,另一个人开始猜位置,
比如猜一个x y,假如这一条恰好覆盖了x y,就要回答他YES,
但是另一个人可以作弊,即移动那一条东西,然后说no,只要一直跟前面说的不矛盾即可,
假如双方都表现的最优,问最少需要几次才能确定1*w那一条的所有位置。
移动的话是不能旋转的,只能平移,可以放到任意位置上 。

解题思路:

假设只有一行,

  c % w == 0 时,每一行按照w一段选择一次,在每一段的中间选择, 那么最坏情况可以在第c/w次说中,锁定在最后一段
  c % w != 0时,第c /w 次猜中一个后,你肯定往两边中的某个方向判断了,这里可以多让你猜错一次。
  多行的情况的话其实就是其他r-1行都没有船的情况,每行需要c / w次
 
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ; int main() {
ofstream fout ("A-large-practice.out");
ifstream fin ("A-large-practice.in");
int i, j, k, T;
int R, C, W; fin >> T;
while (T--) {
fin >> R >> C >> W;
int Ret = R * (C / W);
if (C % W == ) {
Ret += W - ;
} else {
Ret += W;
}
static int numCase = ;
fout << "Case #" << ++numCase << ": " << Ret << endl;
} return ;
}
上一篇:GCJ1C09C - Bribe the *ers


下一篇:TCO 2014 Round 1C 概率DP