Problem Statement | |||||||||||||
Cat and Rabbit are going to play the following game. There are some tiles in a row. Each of the tiles is colored white or black. You are given a stringtiles, describing the initial arrangement of tiles. The characters '.' and '#' represent a white tile and a black tile, respectively. Cat and Rabbit take alternating turns. Cat plays first. In each turn, the following actions must be performed:
| |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | tiles will contain between 1 and 50 characters, inclusive. | ||||||||||||
- | Each character in tiles will be '.' or '#'. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
| |||||||||||||
5) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include<math.h>
#include<vector>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
#define FOR(I,A,B) for (int I=int(A);I<int(B);I++)
#define PUSH(X,N,n) {FOR(q,0,N){X.push_back(n);}}
#define ll _int64
template<class T> T max (T A, T B){if(A>B) return A; else return B;}
template<class T> T min (T A, T B){if(A<B) return A; else return B;}
//#define ll long long
//typedef __int64 ll
#define oo (1<<25)
#define SZ(x) (int)x.size()
#define MAX 100
string rabbit="Rabbit";
string cat="Cat";
class CatAndRabbit{
public:
string getWinner(string tiles)
{
int ok=0;
for(int q=0;q<SZ(tiles);q++)
if(tiles[q]=='#') ok=1;
if(!ok)
return rabbit;
int i,j,ans=0;
for( i=0;i<SZ(tiles);)
{
if(tiles[i]=='#') i++;
else if(tiles[i]=='.')
{
int len=1;
for(int j=i+1;j<SZ(tiles);j++)
{
if(tiles[j]=='.') len++;
else break;
}
i=j;
if(len) ans^=len;
}
}
if(ans) return cat;
else
return rabbit;
}
};
前面讲的错了,看了别人的我突然发现自己弱了。。。。。。。
比如一个数据 2 4 6 好像很难发现到底谁先走完。
后来我想到吧他分解 2 2+2 2+4 可是这样并没什么用。因为 你分解成2+2 别人去3 就没办法了。
可是如果分解成2进制 0010 0100 0110 就可以发现。无论怎么改变其中的一个数,总是可以出现互补的。(就是各个位都有偶数个1)
如 第一步 0001 0100 0110
那么第2步很容易想到 0001 01000101
也就是无论第一个怎么走他都摆脱不了输的命啊