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 ...
随机推荐
- endif、endforeach
<?php if ($a == 5): ?> <div>等于5</div><?php elseif ($a == 6): ?> <div> ...
- 简洁判断一个byte中有多少位为1的bit?
以下是Brian W. Kernighan公开的一个方法 unsigned bit_count(unsigned v) { unsigned int c; //置位总数累计 ; v; c++) { v ...
- Socket异步通信学习三
接下来是客户端部分,采用同步接收模式,在SocketClient项目中新建了一个SynServer类,用于存放socket服务器代码,和AsynServer类似,主要有4个方法: 有一个全局socke ...
- multi-threads synchronization use conditional mutex
#include <pthread.h> int thread_flag; pthread_cond_t thread_flag_cv; pthread_mutex_t thread_fl ...
- 【运维】使用FC命令辅助查杀DLL木马
使用FC命令辅助查杀DLL木马 在windows系统中,system32目录下是木马隐身的好地方,查找起来非常困难,许多木马都削尖了脑袋往那里钻,DLL木马也不例外.针对这一点用户可以在安装好系统和必 ...
- svn服务器的搭建
subversion是优秀的版本管理工具,下面简单介绍svn服务器和客户端的下载.安装.搭建以及使用 一:下载svn服务器和客户端 1:下载地址服务器下载地址:http://subversion.ap ...
- (原创)openvswitch实验连载2-cisco模拟器IOU-Web安装及网络环境配置
IOU的使用可以选择自己到官网https://docs.google.com/file/d/0B2AgRhS2cfxCQ01tN2NrQ0pvNUk/edit下载iou-web 软件,然后部署在lin ...
- 【高性能服务器】Tomcat剖析
引言 Tomcat是一个流行的servlet容器,对于开发人员来说整体和容器打交道有必要花一些时间爱你了解其内部结构.本文将从一下几个方面来剖析其内部结构. 整体结构 连接器 初始化过程 如何处理一个 ...
- Mongodb集群节点故障恢复场景分析
http://blog.csdn.net/zhangzhaokun/article/details/6299527 一个适当配置的Mongodb分片集群是没有单点故障. 本文描述了分片集群中存在的几种 ...
- WebClient外部请求乱码
WebClient web = new WebClient();//创建webclient对象 web.Encoding = Encoding.UTF8;//定义对象语言 var result = w ...