题目描述
虚拟世界要举行一个剑术大会,小Y和小X进入了决赛,决赛进行k个回合。
决赛赛制为地上有n个木桩子,每次小Y或者小X能砍其中一个柱子,他们可以选择砍掉柱子的一截(整数高度)或者是直接砍掉柱子。
每回合中,谁砍掉了最后一个柱子,谁将赢下这个回合。
机制的小Y钞能力买通了裁判,每局都让小Y先出手
输入
第一行一个数k组,
接下来每组第一行为一个整数n,第二行为n个整数,分别为每个柱子的高度h
输出
对于每个回合,如果小Y一定能赢,输出“GG”,若小Y不一定能赢,输出"gl hf"。
样例输入 Copy
3
2
1 3
2
3 3
5
1 2 3 4 5
样例输出 Copy
GG
gl hf
GG
提示
对于100%的数据:1<=k<=10,1<=n<=1001<=n<=1001<=n<=100,1<=h<=10001<=h<=10001<=h<=1000
思路
尼姆博奕
n 堆物品,两个人轮流取,每次取某堆中的不少于1个,最后取完者胜。
结论:将 n 堆物品数量全部异或后结果为 0 则先手必败,否则先手必胜。
代码:
#include<iostream>
#include<string>
#include<map>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define INF 0x3f3f3f3f
#define P pair<int,int>
using namespace std;
typedef long long ll;
const double eps=0.01;
const int N=1e5+10;
const int maxn=5e4+10;
const int mod=1000000007;
int k,n,m;
int main()
{
cin>>k;
while(k--)
{
int f=0;
cin>>n;
for(int i=1;i<=n;i++) cin>>m,f^=m;
if(f) cout<<"GG"<<endl;
else cout<<"gl hf"<<endl;
}
return 0;
}