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 ...
随机推荐
- js之createTextRange方法
createTextRange()方法作用: 主要是用来对一些文本对象进行操作.比如你有一大段文字,都在同一个P标签内,但是你只希望通过JS改变其中的一小部分,这时就可以用createTextRang ...
- LLDB调试基本使用
在平时开发中,我们可能需要调试某些东西,比如查看给服务器发请求时传过去的参数,如果不适用LLDB的话我们用的最多的就是通过NSLog方式去打印,但现在我们可以精简这个步骤,那就是使用LLDB调试命令. ...
- LNMP一键安装包-CentOS 5/6下自动编译安装Nginx,MySQL,PHP
适用环境: 系统支持:CentOS-5 (32bit/64bit).CentOS-6 (32bit/64bit) 内存要求:≥128M 安装了什么: 1.Nginx-1.2.0 2.MySQL 5.5 ...
- SpringMVC框架
一.SpringMVC工作流程图 DispatcherServlet:Spring提供的前端控制器,所有的请求都有经过它来统一分发.在DispatcherServlet将请求分发给Spring Con ...
- [记录]Ubuntu下,使用Shell,简单替换有规律的文件名称
因工作中需要将Flash转为Html5,并且要有动画效果,我将Flash的组件导出Png序列,然后将Png序列拼接成一张雪碧图(Sprite),名字为在生成雪碧图可以排序,需要改成数字名称. 而名字是 ...
- 【Slickflow学习】.NET开源工作流环境搭建(三)
第一次自己写博客文章,大家多多指教.写博客主要记录一下学习的过程,给初学者提供下参考,也留给自己做备忘. Slickflow .NET开源工作流-环境搭建 在VS2010中使用附加进程的方式调试IIS ...
- dede-搜索
<form name="formsearch" action="{dede:global.cfg_cmsurl/}/plus/search.php"> ...
- Plugin with id 'android-apt' not found
解决路径: 1.查看miniSDK最外面的build.gradle 添加这句.具体参考一下demo.谢谢
- mysqlimport 导入文件到数据库命令
mysqlimport -h 172.16.145.125 -u ocetl -pocetl test --fields-terminated-by='|' '/home/ocetl/tmp_use ...
- 快速登录IRC网络聊天室
随便起个NickName,进行人机验证,然后点击Connect进去就可以咯.