This problem can be seen as a special stone game. Take the second example as an example:
1 5 6 7 9 12 14 17
The first pawn cannot be moved to the left. The second pawn can move three grids to the left. The third piece cannot be moved, and so on, you can get a series like this:
0 3 0 0 1 2 1 2 2, the nth number represents the number of steps that the nth piece can move.
Consider moving the second piece to the left, and the original sequence is:
0 2 1 0 1 2 2 2
Isn't that the second pile of stones moved to the third pile of stones on the right? Thus, we can give a new definition of equivalent games:
Given N piles of stones, the number of stones in each pile is non-negative. You can move any stone in heap I to heap I + 1 (1 <= I <N) or discard any stone in heap N. If someone cannot continue the operation, a negative result is returned.
Tiered game: http://blog.csdn.net/hlmfjkqaz/article/details/9612003
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;#define N 1005int main(){ int t,i,j,a[N],n,s,b[N]; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); j=0; for(i=n-1;i>0;i--,j++) { b[j]=a[i]-a[i-1]-1; } s=0; b[n-1]=a[0]-1; for(i=0;i<n;i+=2) s^=b[i]; if(s) puts("Georgia will win"); else puts("Bob will win"); } return 0;}