1. 程式人生 > >4.1.5 Georigia and Bob

4.1.5 Georigia and Bob

Problem description:

  Georigia and Bob 在玩一個遊戲。

  

Input:

  n = 3;

  p = { 1, 2 , 3}

Output:

  Bob wins

思路:將其看成一種Nim遊戲。

 

 

 

Code:

  

int MAX_N = 1000;
int N, P[MAX_N];
void solve(){
    if(N%2==1) p[N++]=0;
    sort(P,P+N);
    int x=0;
    for(int i=0;i+1<N;i+=2
) x^=(P[i+1]-P[i]-1); if(x==0) puts("Bob wins"); else puts("Georgia wins"); }