Address: HDU 4994
In this question, who has the control of the first number greater than 1 is who wins, because it can have two options, one is all, the other is to select n-1, and the other can only select the one left. However, when the number is 1, it cannot be controlled. You can only select this one. At this time, you can choose a number greater than 1 each time, so that you can choose a number greater than 1, because the center is all 1, therefore, it is completely possible to achieve the goal. In this way, as long as you control the first number greater than 1, then the subsequent operation can make the next number greater than 1 the turn of your own, until the last one is also. So it is converted into determining who will be the first to get a number greater than 1. Therefore, you only need to check the number of 1 in front of the first number greater than 1.
The Code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int a[2000];int main(){ int t, n, c, b, i; scanf("%d",&t); while(t--) { scanf("%d",&n); c=b=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { if(a[i]==1) b++; else { c=1; break; } } if(!c) { if(n%2) puts("Yes"); else puts("No"); continue ; } if(b%2) puts("No"); else puts("Yes"); } return 0;}
Bestcoder #9 1002 (hdu4994) Revenge of Nim (game)