Codeforces Round #334 E. Lieges of Legendre(SG)
来源:互联网 发布:it船舶 编辑:程序博客网 时间:2024/06/13 21:18
题意:现在两个人玩游戏,有n堆木棒,每次可以进行两种操作,第一种是将奇数堆的木棒数减一,第二种是将偶数堆的木棒数分为k组,每组的数量为原堆的一半,先不能移动的人输,问谁会赢。
思路:SG。对k分奇偶来求sg函数即可。
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>#include<algorithm>#include<vector>#include<map>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<ctime>#define eps 1e-6#define LL long long#define pii pair<int, int>//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const int MAXN = 110000;//const int INF = 0x3f3f3f3f;int n, a[MAXN];int get_sg1(int m) {if(m==1 || m==3) return 1;if(m == 2) return 0;if(m == 4) return 2;if(m&1) return 0;if(get_sg1(m/2) == 1) return 2;return 1;} int get_sg2(int m) {if(m == 1) return 1;if(m == 2) return 2;if(m & 1) return 0;return 1;}int main() { //freopen("input.txt", "r", stdin);int n, k;cin >> n >> k;for(int i = 1; i <= n; i++) scanf("%d", &a[i]);int ans = 0;if(k&1) {for(int i = 1; i <= n; i++) ans ^= get_sg1(a[i]);} else {for(int i = 1; i <= n; i++)ans ^= get_sg2(a[i]);}if(ans) puts("Kevin");else puts("Nicky"); return 0;}
0 0
- Codeforces Round #334 E. Lieges of Legendre(SG)
- Codeforces Round #334 E. Lieges of Legendre (组合游戏)
- CodeForces 603C/604E Lieges of Legendre SG函数
- codeforces 604 E. Lieges of Legendre (sg函数)
- codeforces 604 E. Lieges of Legendre (sg函数)
- CodeForces 603C Lieges of Legendre (SG函数)
- codeforces 603C. Lieges of Legendre(博弈+SG函数)
- 【Codeforces Round 334 (Div 2)E】【博弈-SG函数】Lieges of Legendre n个数 每次取数-1或者变2x为k个x的博弈
- Codeforces Round #334 (Div. 2) C. Lieges of Legendre
- codeforces #334 div1 603C Lieges of Legendre(博弈)
- [Codeforces 603C]Lieges of Legendre
- nim博弈 Codeforces603C Lieges of Legendre
- codeforces603CLieges of Legendre+SG博弈
- Educational Codeforces Round 5 E. Sum of Remainders(数学)
- Codeforces 768E Game of Stones 博弈SG(打表)
- Codeforces Round #399:E. Game of Stones
- [Codeforces 711E] ZS and The Birthday Paradox (数学+Legendre公式)
- Educational Codeforces Round 4 E. Square Root of Permutation(置换、构造)
- 欢迎使用CSDN-markdown编辑器
- 最长上升子序列
- next()和nextLine()方法的区别
- 使用JDBC在MySQL数据库中快速批量插入数据
- iOS 新特性分列式 之 iOS 7.x - 主要内容:扁平 UI、64位支持、多任务加强、Objective-C 模块支持
- Codeforces Round #334 E. Lieges of Legendre(SG)
- 【JAVA】产生指定范围不重复的随机数
- 在iOS 8中使用UIAlertController
- 小鑫去爬山
- 什么是webservice
- jqGrid 属性、事件全集
- ThinkPHP框架六数据的添加
- 把opencv Mat 按位存成bmp二值图像 (1bit 1pixel)
- spring redis 几种序列化方式的比较