hdu5795 A Simple Nim(博弈找规律)

来源:互联网 发布:小学测验软件 编辑:程序博客网 时间:2024/04/29 08:10

思路:大概手动算了一下sg的值,算到8的时候其实就知道了,当为7的倍数的时候sg值为8,为8的倍数时候sg值为7,然后其他的话都是sg(x)=x的,然后异或异或就可以了


#include<bits/stdc++.h>using namespace std;const int maxn= 1e6+7;#define LL long longint a[maxn];int main(){int T;scanf("%d",&T);while(T--){int n;LL sg = 0;scanf("%d",&n);for(int i = 1;i<=n;i++){LL temp;scanf("%lld",&temp);if(temp%8==0)temp--;else if(temp%8==7)temp++;            sg^=temp;}if(sg==0)printf("Second player wins.\n");elseprintf("First player wins.\n");834078}}


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 1T100, 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[n1], representing heaps with s[0],s[1],...,s[n1] objects respectively.(1n106,1s[i]109)
 

Output
For each test case,output a line whick contains either"First player wins."or"Second player wins".
 

Sample Input
224 431 2 4
 

Sample Output
Second player wins.First player wins.
 

Author
UESTC
 


0 0