/** 題目:A Simple Nim 鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5795 題意:給定n堆石子,每堆有若干石子,兩個人輪流操作,每次操作可以選擇任意一堆取走任意個石子(不可以為空) 或者選擇一堆,把它分成三堆,每堆不為空。求先手必勝,還是后手必勝。 思路: 組合游戲Nim; 計算出每一堆的sg值,然后取異或。異或和>0那么先手,否則后手。 對於每一堆的sg值求解方法: 設:sg(x)表示x個石子的sg值。sg(x) = mex{sg(x-1),sg(x-2),...,sg(0),sg(a)^sg(b)^sg(c) |(a+b+c==x)} 當sg(0) = 0; sg(1) = 1; sg(2) = 2; sg(x>=3)就要通過上面式子算出來了。 通過打表可以發現規律。 當x>=3.如果x是8的倍數,那么sg=x-1. 如果(x+1)是8的倍數,那么sg=x+1. */ #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> P; const int maxn = 1e6+10; const int mod = 1e9+7; int T, n; int main() { cin>>T; while(T--) { scanf("%d",&n); int ans = 0; for(int i = 0; i < n; i++){ int x; scanf("%d",&x); if(x%8==0&&x!=0){ ans ^= x-1; }else { if((x+1)%8==0){ ans ^= x+1; }else { ans ^= x; } } } printf("%s\n",ans?"First player wins.":"Second player wins."); } return 0; }