HDU 1850 Being a Good Boy in Spring Festival

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

1
2
3
4
5
6
7
8
9
10
11
12
13
#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;   

HDU 1850 Being a Good Boy in Spring Festival,布布扣,bubuko.com

HDU 1850 Being a Good Boy in Spring Festival

上一篇:微信小程序支付以及微信退款开发


下一篇:CentOS 7 zabbix实现微信报警