码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 15C. Industrial Nim

时间:2017-03-11 20:35:53      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:pre   ret   problems   cst   include   stdout   force   blog   style   

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


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

考虑利用异或的性质。

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

在$x$是偶数时${x^(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

 

codeforces 15C. Industrial Nim

标签:pre   ret   problems   cst   include   stdout   force   blog   style   

原文地址:http://www.cnblogs.com/Dragon-Light/p/6536022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!