HDU 1850 Being a Good Boy in Spring Festival

题解:尼姆博弈,SG(i)=i,要使当前堆可取,则数量必须大于其余所有堆的SG异或值,这样才可以减到其SG值使总异或值为0,又不可不取,所以不能取等号。

#include <cstdio>    

using namespace std;    

int SG[105];    

int main(){    

    int n,sum,cnt,i;    

    while (scanf("%d",&n),n){    

        sum=cnt=0;    

        for(i=0;i<n;i++)scanf("%d",&SG[i]),sum^=SG[i];       

        for(i=0;i<n;i++){sum^=SG[i];if(SG[i]>sum)cnt++;sum^=SG[i];}    

        printf("%d\n",cnt);    

    }    

    return 0;    

}  

你可能感兴趣的:(spring)