题目链接

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函数的更多相关文章

  1. Codeforces Round #334 (Div. 1) C. Lieges of Legendre

    Lieges of Legendre 题意:有n堆牛,每堆有ai头牛.两个人玩一个游戏,游戏规则为: <1>从任意一个非空的堆中移走一头牛: <2>将偶数堆2*x变成k堆,每堆 ...

  2. 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 + ...

  3. 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 ...

  4. 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 ...

  5. CF# 334 Lieges of Legendre

    C. Lieges of Legendre time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  7. 【转】博弈—SG函数

    转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...

  8. 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)运算 ...

  9. POJ2425 A Chess Game[博弈论 SG函数]

    A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3917   Accepted: 1596 Desc ...

随机推荐

  1. hibernate 简单查询

    1. 查询整个映射对象所有字段 //直接from查询出来的是一个映射对象,即:查询整个映射对象所有字段           String hql = "from Users";   ...

  2. oracle查看系统资源占用情况

    1,连上服务器,使用top命令,可以查看cpu使用率以及内存的使用情况等等,还有当前各用户的使用情况 2,用pl/sql developper,tool里面选sessions,就可以看到当前sessi ...

  3. FPGA开发(1)

    `timescale ns / ns module system_ctrl ( //globol clock input clk, input rst_n, //synced signal outpu ...

  4. C#:占位符的例子

    在c#中有两种方式可以输出多个字符. static void Main() { string c=Console.ReadLine(); string d=Console.ReadLine(); Co ...

  5. Global.asax 文件说明

    引用 来自  http://www.cnblogs.com/jianshao810/archive/2011/02/03/1948912.htm 在网上找了N多相关的东西总说的不够细,现在终于找到了. ...

  6. Java中如何把两个数组合并为一个

    在Java中,如何把两个String[]合并为一个? 看起来是一个很简单的问题.但是如何才能把代码写得高效简洁,却还是值得思考的.这里介绍四种方法,请参考选用. 一.apache-commons 这是 ...

  7. Java学习之finally关键字总结

    Java中的final关键字非常重要,它可以应用于类.方法以及变量.这篇文章中我将带你看看什么是final关键字?将变量,方法和类声明为final代表了什么?使用final的好处是什么?最后也有一些使 ...

  8. jQuery 源码分析和使用心得 - 序

    众所周知, jQuery (个人简称为jq) 在前端开发中占有着非常重要的地位, 可以说jQuery的存在大大降低了学习网页设计和交互的门槛, 他的简单的语法和顺畅的使用逻辑激发了人们强烈的学习兴趣, ...

  9. python----设置默认编码

    问题:python的默认编码是ascii.在处理中文的时候可能会出现乱码的情况:这个时候我们就需要把编码设置为对应的编码了. 解决方案: 对python文件的头部做如下修改 import sys re ...

  10. Python 模块的一般处理

    因为Python模块在被导入时,定义在模块中的顶级代码是会被执行的!如果我们想改变这种运行方向可以这样做: if __name__ == '__main__':#当这个模块作为主程序时__name__ ...