codeforces 15C. Industrial Nim

题目链接:http://codeforces.com/problemset/problem/15/C


$NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多。

考虑利用异或的性质。

一共给出了$n$段石头堆,每段中石头堆的数量是连续的。

在$x$是偶数时${x~~xor~~(x+1)=1}$,利用这个性质我们就可以${O(1)}$的算出每一段石头的异或和。


 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<vector>
 5 #include<cstdlib>
 6 #include<cmath>
 7 #include<cstring>
 8 using namespace std;
 9 #define maxn 10010
10 #define llg long long 
11 #define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
12 llg n,m,T,ans,x;
13 int main()
14 {
15     yyj("nim");
16     cin>>T;
17     while (T--)
18     {
19         llg xo=0;
20         cin>>x>>n;
21         m=x+n-1;
22         if (x%2) xo^=x,n--;
23         if ((n/2)%2) xo^=1;
24         if (n%2) xo^=m;
25         ans^=xo;
26     }
27     if (ans) cout<<"tolik";else cout<<"bolik";
28     return 0;
29 }
30 //对于一个数x%2=0,x^(x+1)=1

 

转载于:https://www.cnblogs.com/Dragon-Light/p/6536022.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值