Problem Description
Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more interesting,players can separate one heap into three smaller heaps(no empty heaps)instead of the picking operation.Please find out which player will win the game if each of them never make mistakes.
Input
Intput contains multiple test cases. The first line is an integer
1≤T≤100
, the number of test cases. Each case begins with an integer n, indicating the number of the heaps, the next line contains N integers
s[0],s[1],....,s[n−1]
, representing heaps with
s[0],s[1],...,s[n−1]
objects respectively.
(1≤n≤106,1≤s[i]≤109)
Output
For each test case,output a line whick contains either"First player wins."or"Second player wins".
Sample Input
2 2 4 4 3 1 2 4
Sample Output
Second player wins. First player wins.
SG函数。对于每个x的sg值
如果x%8==0 那么x--,如果x%8==7 则x++
其余x的sg值就为x
这个可以打表找规律得出。。如果要证明的话并不是太会。。
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T>0)
{
T--;
int n;
scanf("%d",&n);
int i;
int ans=0,x;
for(i=1;i<=n;i++)
{
scanf("%d",&x);
if(x%8==0)
x--;
else if(x%8==7)
x++;
ans^=x;
}
if(ans==0)
printf("Second player wins.\n");
else
printf("First player wins.\n");
}
return 0;
}