题目链接

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. APP-SQLAP-10771

    用户在匹配 PO时,其中一张AP INVOICE不管进行何种更新操作,总是报:APP-SQLAP-10771:Could not reserve record(不能保留记录) 错误. 而且这个发票问题 ...

  2. iOS开发笔记:编译时出现的错误和解决办法

    1."std::ios_base::Init::~Init()", referenced from 出现这样的编译问题,是需要再加进libstdc++.dylib和libstdc+ ...

  3. js 控制台的错误提示

    错误:程序运行过程中发生的异常状态 导致程序停止运行——异常 错误处理:当程序发生错误时,保证程序不退出的机制 发生错误时,程序会自动创建一个Error对象: Error对象中仅封装了错误的信息 js ...

  4. 关于webapp中的文字单位的一些捣腾

    前言 文字是网页内容的一枚大将,我们无时无刻都在看着它,只要是你盯屏幕上的任何一个地方都会有文字.地铁上无时无刻都在盯着屏幕上的人对于文字更为敏感,太大不行,太小TN又看不清上面到底在说什么,有时候车 ...

  5. php随笔1-php图片处理

    php图片处理的知识内容 upload_image.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN ...

  6. spring4之依赖注入的三种方式

    1.Setter注入 <bean id="helloWorld" class="com.jdw.spring.beans.HelloWorld"> ...

  7. PowerShell入门(一):PowerShell能干什么?

    原文链接:http://www.cnblogs.com/ceachy/archive/2013/01/30/WhatCanPowerShellDo.html PowerShell能干什么呢?就像序言中 ...

  8. 编程工具篇——Vim

    配置 配置文件位于:/etc/vim/vimrc(添加配置在文件末尾输入代码即可) 常用配置 配色方案 :colorscheme ron(其中ron为我的配色方案,也可以选择其他,软件中自带配色文件全 ...

  9. Linux 安装xtrabackup的依赖问题

    问题: 尝试安装xtrabackup rpm -ivh percona-xtrabackup-2.2.11-1.el7.x86_64.rpm 报错 perl(DBD::mysql) 被 percona ...

  10. 16.java.lang.InterruptedException

    java.lang.InterruptedException 被中止异常 当某个线程处于长时间的等待.休眠或其他暂停状态,而此时其他的线程通过Thread的interrupt方法终止该线程时抛出该异常 ...