Address: poj 1704
This question is really clever .. In this way, it can be converted into a classic Nim model.
This question can be paired from left to right. If there are odd numbers, the leftmost is paired with 0. Then, whenever the other party moves the first of a pair, you can always move the other one back. Therefore, this is unaffected. Only the numbers of spaces in the middle of each pair are affected. This is converted into a (n + 1)/2) Heap stone game. The number of stones in each heap is the number of spaces between each pair of points. Then we use an exclusive or solution.
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, i, s, j, sum; scanf("%d",&t); while(t--) { scanf("%d",&n); a[0]=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); } sort(a+1,a+n+1); if(n&1) { s=0; } else s=1; sum=0; for(i=s;i<=n;i+=2) { sum^=a[i+1]-a[i]-1; } if(!sum) puts("Bob will win"); else puts("Georgia will win"); } return 0;}
Poj 1704 Georgia and Bob (NIM game theory)