C. Lieges of Legendre
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:

  1. Remove a single cow from a chosen non-empty pile.
  2. Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each.

The player who removes the last cow wins. Given nk, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.

Input

The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).

The second line contains n integers, a1, a2, ... an (1 ≤ ai ≤ 109) describing the initial state of the game.

Output

Output the name of the winning player, either "Kevin" or "Nicky" (without quotes).

Sample test(s)
input
2 1
3 4
output
Kevin
input
1 2
3
output
Nicky
Note

In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other.

题意:给出n,k,表示有n堆石子,石子数目分别为a1.a2...an,

每次一个人可以在任意一堆拿掉一个石子,或者,如果某堆石子是偶数个的话,设为2*x个,可以分为k堆x个的石子

取得最后一颗石子即为胜利。

问先手赢还是后手赢。

分析:显然,根据sg函数的定义,sg函数定义为当前状态第一个达不到的状态。

其中,石子游戏用石子数目当作当前状态。

如果有多堆石子,则将它们异或起来。

显然,如果k是偶数的话,考虑一堆的情况,那么奇数必胜,偶数必败,这个可以用数学归纳法证明。那么如果有多堆的情况就考虑一下奇数堆和偶数堆的数目即可。

如果k为奇数,就按照sg函数的定义做就好。

 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} int n, k, state; inline int Sg(int x)
{
if(k & )
{
if(x < )
{
if(x == ) return ;
if(x == || x == ) return ;
return ;
}
if(x & ) return ;
return Sg(x / ) == ? : ;
}
else
{
if(x == ) return ;
if(x == ) return ;
return (x & ) ^ ;
}
} inline void Input()
{
scanf("%d%d", &n, &k);
for(int i = ; i < n; i++)
{
int x;
scanf("%d", &x);
state ^= Sg(x);
}
} inline void Solve()
{
puts(state ? "Kevin" : "Nicky");
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}

CF# 334 Lieges of Legendre的更多相关文章

  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. CF# 334 Moodular Arithmetic

    B. Moodular Arithmetic time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. CF# 334 Alternative Thinking

    A. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. codeforces 603C. Lieges of Legendre sg函数

    题目链接 n堆石子, 可以拿走一堆中的一颗, 或者将一堆数量为2*x的石子分为k堆x个的石子.k由题目给出. k分奇偶讨论. k为偶数时,k堆x个的石子异或结果为0: k为奇数时, k堆x个石子异或结 ...

  6. CF 334 div.2-D Moodular Arithmetic

    思路: 易知k = 0的时候答案是pp-1,k = 1的时候答案是pp. 当k >= 2的时候,f(0) = 0,对于 1 <= n <= p - 1,如果f(n)确定,由题意可知f ...

  7. Lieges of Legendre CodeForces - 603C (博弈论,SG找规律)

    大意: 给定$n$堆石子, 两人轮流操作, 每次操作两种选择 $(1)$任选非空堆拿走一个石子 $(2)$任选石子数为$2x(x>0)$的一堆, 替换为$k$堆$x$个石子. ($k$给定) 最 ...

  8. cf Round 603

    A.Alternative Thinking(思维) 给出一个01串,你可以取反其中一个连续子串,问取反后的01子串的最长非连续010101串的长度是多少. 我们随便翻一个连续子串,显然翻完之后,对于 ...

  9. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

随机推荐

  1. Java ANT build.xml

    详情请参考:http://www.cnblogs.com/xionghui/archive/2012/03/13/2393679.html

  2. 关于内存管理/set/get方法

    MRC状态下 1 任何继承NSObject的对象,存放于堆控件中,都需要手动管理内存 .2 基本数据类型放到栈中,对象放到堆空间中,内存是有系统管理的.(int\float\enum\struct) ...

  3. mysqli扩展库的预处理技术 mysqli stmt

    //预编译演示 //1,创建mysqli对象 $mysqli=new mysqli("localhost","root",""," ...

  4. gzip

    gzip -c 将输出写到标准输出上,并保留原文本 gzip * : 把当前目录中的每个文件压缩成.gz文件 [root@NB gzip]# ls mysql-bin. mysql-bin..tar ...

  5. MVC学习笔记---各种上下文context

    0  前言 AspNet MVC中比较重要的上下文,有如下: 核心的上下文有HttpContext(请求上下文),ControllerContext(控制器上下文) 过滤器有关有五个的上下文Actio ...

  6. MVC - 11(下)jquery.tmpl.js +ajax分页

    继续 mvc-11(上).dto:http://www.cnblogs.com/tangge/p/3840060.html jquery.tmpl.js 下载:http://pan.baidu.com ...

  7. 阿里云 SWAP

    https://yq.aliyun.com/articles/52098 https://www.kejianet.cn/aliyun-swap/

  8. Nginx详解(一)

    1.Nginx是什么? Nginx就是反向代理服务器. 首先我们先来看看什么是代理服务器,代理服务器一般是指局域网内部的机器通过代理服务发送请求到互联网上的服务器,代理服务器一般作用于客户端.比如Go ...

  9. 发现一php木马代码

    <?php ;//无需验证密码! $shellname='hello~地球~猴子星球欢迎你 '; define('myaddress',__FILE__); error_reporting(E_ ...

  10. 【JAVA IO流之字节流】

    字节流部分和字符流部分的体系架构很相似,有四个基本流:InputStream.OutputStream.BufferedInputStream.BufferedOutputStream,其中,Inpu ...