题目链接:
选我选我
就是有n堆物品,然后只有一堆物品完全选完后,才能选好后面的,看最后谁赢。
思路:
确定第一个不为1的是轮到谁,如果谁得到了这个优势,那么他就必胜。。因为他可以人为控制后面的顺序了。。
题意:
题目:
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 Description
Nim 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.
Input
The 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
Output
For each test case, output “Yes” if the first player can always win, otherwise “No”.
Sample Input
2 1 2 2 1 1
Sample Output
Yes No
Source
Recommend
heyang | We have carefully selected several similar problems for you: 4996 4995 4992 4991 4990
代码:
#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 0x3f3f3f3f using 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; }