牛客小白月赛2 E题 是是非非 (尼姆博弈)

题目链接:https://www.nowcoder.com/acm/contest/86/E

解题思路:由尼姆博弈我们可以知道,如果所有堆的石子数量异或为0,那么先手必败,否则先手必胜。

由异或我们可以知道,x异或两次相同的值,x值不变。

代码:

 1 #include<iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 int a[100500];
 5 int main(){
 6     int n,q;
 7     cin>>n>>q;
 8     int sum=0;
 9     for(int i=1;i<=n;i++){
10         scanf("%d",a+i);
11         sum=sum^a[i];
12     }
13     while(q--){
14         int x,y;
15         scanf("%d%d",&x,&y);
16         sum=sum^a[x];
17         a[x]=y;
18         sum=sum^a[x];
19         if(sum==0){
20             cout<<"Li"<<endl;
21         }else{
22             cout<<"Kan"<<endl;
23         }
24     }
25     return 0;
26 }

 

转载于:https://www.cnblogs.com/ISGuXing/p/8908082.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值