Question link: select me
There are n heaps of items, and only after a bunch of items are completely selected can we select the ones that follow, to see who wins.
Ideas:
Determine who is the first to be 1. If anyone gets this advantage, they will win .. Because he can manually control the subsequent sequence .. Question: Revenge of Nim
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 259 accepted submission (s): 119
Problem descriptionnim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. on each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.
--- Wikipedia
Today, Nim takes revenge on you. the rule of the game has changed a little: The player must remove the objects from the current head (first) heap. only the current head heap is empty can the player start to remove from the new head heap. as usual, the player who takes the last object wins.
Inputthe first line contains a single integer T, indicating the number of test cases.
Each test case begins with an integer N, indicating the number of heaps. then n integer AI follows, indicating the number of each heap successively, and the player must take objects in this order, from the first to the last.
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= n <= 1 000
3. 1 <= AI <= 1 000 000 000
Outputfor each test case, output "yes" if the first player can always win, otherwise "no ".
Sample Input
21221 1
Sample output
YesNo
Sourcebestcoder round #9
Recommendheyang | we have carefully selected several similar problems for you: 4996 4995 4992 4991
Code:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<vector>#include<cmath>#include<string>#include<queue>#define eps 1e-9#define ll long long#define INF 0x3f3f3f3fusing namespace std;const int maxn=1000+10;int a[maxn];int main(){ int t,n,cnt,ok; scanf("%d",&t); while(t--) { cnt=ok=0; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { if(a[i]==1) cnt++; else { ok=1; break; } } if(ok) { if(cnt%2) puts("No"); else puts("Yes"); } else { if(cnt%2) puts("Yes"); else puts("No"); } } return 0;}
Hdu4994revenge of Nim (game)