CF# 334 Lieges of Legendre
2 seconds
256 megabytes
standard input
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:
- Remove a single cow from a chosen non-empty pile.
- 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 n, k, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.
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 the name of the winning player, either "Kevin" or "Nicky" (without quotes).
2 1
3 4
Kevin
1 2
3
Nicky
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的更多相关文章
- 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 + ...
- CF# 334 Moodular Arithmetic
B. Moodular Arithmetic time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CF# 334 Alternative Thinking
A. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforces 603C. Lieges of Legendre sg函数
题目链接 n堆石子, 可以拿走一堆中的一颗, 或者将一堆数量为2*x的石子分为k堆x个的石子.k由题目给出. k分奇偶讨论. k为偶数时,k堆x个的石子异或结果为0: k为奇数时, k堆x个石子异或结 ...
- 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 ...
- Lieges of Legendre CodeForces - 603C (博弈论,SG找规律)
大意: 给定$n$堆石子, 两人轮流操作, 每次操作两种选择 $(1)$任选非空堆拿走一个石子 $(2)$任选石子数为$2x(x>0)$的一堆, 替换为$k$堆$x$个石子. ($k$给定) 最 ...
- cf Round 603
A.Alternative Thinking(思维) 给出一个01串,你可以取反其中一个连续子串,问取反后的01子串的最长非连续010101串的长度是多少. 我们随便翻一个连续子串,显然翻完之后,对于 ...
- 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 ...
随机推荐
- 重写List集合的ToString方法
重写方法: public class MyList<T> : List<T> where T : IConvertible { public override string T ...
- Lambda表达式与标准运算符查询
class Program { static void Main(string[] args) { //Lambda表达式输出List集合每一项 List<string> list = n ...
- python基础——获取对象信息
python基础——获取对象信息 当我们拿到一个对象的引用时,如何知道这个对象是什么类型.有哪些方法呢? 使用type() 首先,我们来判断对象类型,使用type()函数: 基本类型都可以用type( ...
- C++异常层次结构图
- nyoj998(euler)
题意:题意:给出n和m,求满足条件gcd(x, n)>=m的x的gcd(x, n)的和,其中1<=x<=n,1<= n, m <= 1e9:思路:此题和nyoj1007差 ...
- css设置网页文本选中样式
网页的默认的文本选中颜色是蓝底白字(大多应该是吧),这个样子: 感觉并不是特别好看,可以通过CSS3的一个特性,一个CSS3的伪类选择器::selection来设置文本被选中时的状态,比如本博客的主题 ...
- Shell编程基础教程7--脚本参数的传递
7.脚本参数的传递 7.1.shift命令 简介: shift n 每次将参数位置向左偏移n位 例子 #!/bin/bash us ...
- Yii 同域名的单点登录 SSO实现
SSO (Single Sign-on) 顾名思义就是几个子项目共用一个登录点. 原理简单来说就是服务端session 共享, 客户端跨域cookies. 实现非常简单,protected/confi ...
- VS2015 Xamarin for iOS
VS2015环境配置 VS2015安装不多说.其实Xamarin 和微软感觉并不是什么好基友,Xamarin以前一直像个可怜的娃,以插件的形式寄生于VS中.现在只不过形势稍微好点了,VS2015 在明 ...
- C# Settings使用小结
本篇博客将介绍C#中Settings的使用. 首先介绍一个桌面程序中的例子,当我们新安装一个软件,软件启动后会有例如新手指导等窗体弹出来,每次都需要自己去关闭它.当然这些软件都会提供例如不再显示等功能 ...