codeforces 15C. Industrial Nim
生活随笔
收集整理的這篇文章主要介紹了
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
總結
以上是生活随笔為你收集整理的codeforces 15C. Industrial Nim的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于input单选框的radio属性
- 下一篇: HDU 4635 Strongly co