Codeforces Round #334 (Div. 1) C. Lieges of Legendre
题意:有n堆牛,每堆有ai头牛。两个人玩一个游戏,游戏规则为:
<1>从任意一个非空的堆中移走一头牛;
<2>将偶数堆2*x变成k堆,每堆x头牛(可以增加牛的个数)
移走最后一头牛的人获胜;
数据:n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).a1, a2, ... an (1 ≤ ai ≤ 109)
分析:这显然是SG函数与SG定理的应用;
SG函数与SG定理:SG[x] = mex(S);其中S是所有x的后继状态的SG函数值的集合,mex(S) 表示不在S内的最小非负整数;SG[x] = 0当且仅当x为必败状态;
游戏和的SG函数等于各子游戏的SG函数的nim和(nim和就是异或操作)
理解:对于初始的状态要求出SG函数值,就必须等到所有的子状态的SG函数,但是由于ai的值太大(是对操作1而言的),这是一般需要打表找出规律;即数组ret的两维表示k偶奇时前5个值的SG值,并且容易发现不论k的奇偶,当i >= 5 且 i为奇数时,ai = 0;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<time.h>
#include<stack>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define MSi(a) memset(a,0x3f,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1|1
typedef __int64 ll;
template<typename T>
void read1(T &m)
{
T x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
if(a>) out(a/);
putchar(a%+'');
}
int k;
int ret[][] = {{,,,,},{,,,,}};
int mex(int state)
{
if(state < ) return ret[k%][state];// G[0] = 0,G[1] = 1;
int a,b;
if(state & ){
return ;
}else{
if(k & ) b = mex(state/);
else b = ;
a = ;// mex(state - 1) = 0;
if(a != && b != ) return ;
if(a != && b != ) return ;
return ;
}
}
int main()
{
int n,ans = ,x;
read2(n,k);
rep1(i,,n){
read1(x);
//ans = 0;
ans ^= mex(x);//mex(i)用来找规律;
//cout<<ans<<" ";
}
printf("%s",ans?"Kevin":"Nicky");
return ;
}
Codeforces Round #334 (Div. 1) C. Lieges of Legendre的更多相关文章
- 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 ...
- Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数
D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/60 ...
- Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心
C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...
- Codeforces Round #334 (Div. 2) B. More Cowbell 二分
B. More Cowbell Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/probl ...
- 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)
题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...
- 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)
题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...
- Codeforces Round #334 (Div. 2)
水 A - Uncowed Forces #include <bits/stdc++.h> using namespace std; typedef long long ll; const ...
- Codeforces Round #334 (Div. 1) B. Moodular Arithmetic
B - Moodular Arithmetic 题目大意:题意:告诉你p和k,其中(0<=k<=p-1),x属于{0,1,2,3,....,p-1},f函数要满足f(k*x%p)=k*f( ...
- Codeforces Round #334(div.2) A
A. Uncowed Forces time limit per test 1 second memory limit per test 256 megabytes input standard in ...
随机推荐
- Hibernate连接MySQL数据库乱码相关问题
1.查看MySQL字符编码 >show variables like 'character%'; #执行编码显示 其中character_set_client,character_set_res ...
- SerialPort基本小例
SerialPort是用于串口通信的控件与VB6中的MSCOMM控件相似,使用很方便... vb.net CodeImports System.IO.PortsImports System.TextP ...
- ASP.NET MVC 4 Ajax上传文件
这两天一直纠结着表单的问题.想在一个表单里实现三个功能: 输入查询条件,点击查询: 导出查询数据: 上传文件: 方法有很多,乱花渐欲迷人眼,尝试了很多,无果.大致说的是,给不同按钮写js代码,在js代 ...
- JS 乱记
JS 中不存在块级作用域,也就是说在全局作用域下 if ,for 语句中用 var 声明的变量是全局变量. JS 中浮点数运算的值为近似值,比如:0.1 + 0.2 不等于 0.3 ,所以避免使用浮点 ...
- Android屏幕保持唤醒状态
我们程序偶尔会有需要屏幕一直或较长时间的保持唤醒状态,而用户的睡眠时间又设置的比较短.这时可能会对程序以及用户的使用造成一定的影响.在Android中有两种方法,可以让我们在我们需要保持唤醒的页面长时 ...
- Mysql_存储功能
先上一段代码: -->DELIMETER; ----加上这一句:DELIMETER的作用是设定客户机的分隔符,表示用//包含的是一段程序,一起执行,而不是见到“:”就执行 结束的时候写上 ...
- DOM方式解析XML文件实例
books.XML文件: <?xml version="1.0" encoding="utf-8"?><bookstore> &l ...
- 文本框限制输入类型<input>的输入框
最近在开发完一个项目后,又测试人员测试bug,然后我根据他们测试出来的bug一个一个的改,然后就遇到了一个问题,文本框是用来搜索,但是,比如这个文本框是用来搜索年龄的区间,输入条件的时候,如果输入了非 ...
- GNU glibc
在线G-lib-c(GNU C Library库)网站 参考: 1.bitsToTypes
- CI获取ip的API
header("Content-type:text/html;charset=utf-8"); // p($this->input->ip_address()); // ...