codeforces 603C. Lieges of Legendre sg函数
n堆石子, 可以拿走一堆中的一颗, 或者将一堆数量为2*x的石子分为k堆x个的石子。k由题目给出。
k分奇偶讨论。 k为偶数时,k堆x个的石子异或结果为0; k为奇数时, k堆x个石子异或结果与mex(x)相等, 然后打不同的sg表找规律, 打表程序看代码。
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int sg[];
/*int mex1(int x) {
if(~sg[x])
return sg[x];
int vis[105];
mem(vis);
vis[mex1(x-1)] = 1;
if(x%2==0) //k为奇数
vis[mex1(x/2)] = 1;
for(int i = 0; ; i++)
if(!vis[i])
return sg[x] = i;
}
int mex2(int x) { //k为偶数
if(~sg[x])
return sg[x];
int vis[105];
mem(vis);
vis[mex2(x-1)] = 1;
if(x%2==0)
vis[0] = 1;
for(int i = 0; ; i++)
if(!vis[i])
return sg[i] = i;
}*/
int mex2(int x) {
if(x<=) {
return x;
}
if(x&)
return ;
return ;
}
int mex1(int x) {
if(x<=) {
if(x&)
return ;
if(x==)
return ;
return ;
}
if(x&)
return ;
int tmp = mex1(x/);
if(tmp==)
return ;
return ;
}
int main()
{
mem1(sg);
/*sg[0] = 0;
for(int i = 0; i<=100; i++)
sg[i] = mex1(i);
for(int i = 0; i<=100; i++) {
printf("[%d:%d]\n", i, sg[i]);
}*/
int n, k, x, ans = ;
cin>>n>>k;
while(n--) {
scanf("%d", &x);
if(k&)
ans ^= mex1(x);
else
ans ^= mex2(x);
}
if(!ans) {
puts("Nicky");
} else {
puts("Kevin");
}
return ;
}
codeforces 603C. Lieges of Legendre sg函数的更多相关文章
- Codeforces Round #334 (Div. 1) C. Lieges of Legendre
Lieges of Legendre 题意:有n堆牛,每堆有ai头牛.两个人玩一个游戏,游戏规则为: <1>从任意一个非空的堆中移走一头牛: <2>将偶数堆2*x变成k堆,每堆 ...
- codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre
C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...
- Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)
D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...
- Educational Codeforces Round 68 (Rated for Div. 2)D(SG函数打表,找规律)
#include<bits/stdc++.h>using namespace std;int sg[1007];int main(){ int t; cin>>t; while ...
- CF# 334 Lieges of Legendre
C. Lieges of Legendre time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- 【转】博弈—SG函数
转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...
- HDU 1848 Fibonacci again and again【SG函数】
对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算 ...
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
随机推荐
- ES6笔记③
1.查找关键字 includes(); 返回布尔值 //①:includes -->代替-->indexof-->返回布尔值 var str = "769909303&q ...
- java list 去除 重复值
一: Hastset根据hashcode判断是否重复,数据不会重复 Java代码 /** List order not maintained **/ public static void remove ...
- JVM学习之类的卸载机制
类的生命周期 当Sample类被加载.连接和初始化后,它的生命周期就开始了,当代表Sample类的Class对象不再被引用,即不可触及时,Class对象就会结束生命周期,Sample类在方法区内的数据 ...
- CodeForces 379 D. New Year Letter
枚举开头结尾的字母,枚举ac的个数,总AC个数就是两个Fibonacci数列的和..... D. New Year Letter time limit per test 1 second memory ...
- Android 数据库ORM框架GreenDao学习心得及使用总结<一>
转: http://www.it165.net/pro/html/201401/9026.html 最近在对开发项目的性能进行优化.由于项目里涉及了大量的缓存处理和数据库运用,需要对数据库进行频繁的读 ...
- jenkins 配置安全邮件
Jenkins网页设置界面只支持SSL协议 ,对于STARTTLS协议,需要修改jenkins的配置文件去支持基于TLS的SMTP认证 1.修改jenkins配置文件 打开jenkins配置文件/et ...
- struts2笔记07-action扩展名
1.action扩展名 默认扩展名可以去/org/apache/struts2/default.properties中查看 struts.action.extension=action,, defau ...
- hdu 4512 吉哥系列故事——完美队形I LCIS
题目链接 给一个数列, 在里面选出一些数组成一个对称的数列, 数的顺序不能打乱. 使得左半边是一个严格递增的数列, 右边递减, 并且a[i] = a[n-i+1]. 就是一个对称的LCIS.. #in ...
- Traveling
Problem J: Traveling Time Limit: 1 Sec Memory Limit: 32 MB Description SH likes traveling around th ...
- ELMAH+MVC4+SQLite 错误日志
任何程序我想无论是在调试开发阶段还是上线运营阶段,都能够使人“放心”,不要出什么意外,也不要玩什么心跳:那就需要比较到位和及时的异常与错误日志模块. 本文将简要描述ELMAH.MVC4与SQLite这 ...