Joyless Game(公式)-JavierWu

发布于 2019-08-06  10 次阅读


Joyless Game(公式)

Playing games is the best way to improve flexibility, critical thinking and strategy.

To become the best Pokenom player, Bash is playing some games with his Pokenom Chikapu.

Bash writes down a string S containing only lowercase English letters. No 2 consecutive characters in S are equal.

Bash and Chikapu alternatively take turns to play.

In each turn, a player must delete one character in S. There are 2 conditions:

The first and last characters can not be deleted.

After the character is deleted, in the new string, no 2 consecutive characters are equal.

The player who cannot delete a character loses.

Chikapu plays first.

After playing 109+7 games, Chikapu won 0 games and lost all 109+7 times. Chikapu thinks that Bash is cheating, by selecting a string S such that Bash always wins.

Given some string S, can you help determine who would win the game, if they both play optimally?

Input
The first line of input contains the integer T — the number of test cases (1≤T≤20).

The next T lines each contain exactly one string S (3≤|S|≤105).

Output
For each test case, print on one line the name of the winner, if they both play optimally. Please note that this problem uses case-sensitive checker.

Sample Input 1
2
vietnam
icpc

Sample Output 1

Chikapu
Bash

本题主要是公式规律。
通过题面也可以看出,(After playing 109+7 games, Chikapu won 0 games and lost all 109+7 times. Chikapu thinks that Bash is cheating, by selecting a string S such that Bash always wins.)总有一个特殊的字符串能让他赢,可以了解到,本题是个公式题目。
推算可知,当首尾字母不相同时候,这时候,只需要看看此时字符串位数有多少,因为最优拿法只有2种,要么都拿,要么都不拿。由此可知,当字符串长度为奇数时,Chikapu一定获胜,反之Bash一定获胜。而如果首尾字母相同的话,结论就会是反的,因为首尾字母相同,相当于字符串缩小了一个单位。所以,当字符串为奇数时,Bash一定获胜,反之Chikapu一定获胜。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		string s;
		cin >> s;
		if (s[0] == s[s.size() - 1])
		{
			if (s.size() % 2 == 0)
				cout << "Chikapu" << endl;
			else
				cout << "Bash" << endl;
		}
		else
		{
			if (s.size() % 2 == 0)
				cout << "Bash" << endl;
			else
				cout << "Chikapu" << endl;
		}
	}
	return 0;
}
届ける言葉を今は育ててる
最后更新于 2019-08-06