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的更多相关文章

  1. 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 ...

  2. Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数

    D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/60 ...

  3. Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心

    C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...

  4. 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 ...

  5. 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)

    题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...

  6. 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)

    题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...

  7. Codeforces Round #334 (Div. 2)

    水 A - Uncowed Forces #include <bits/stdc++.h> using namespace std; typedef long long ll; const ...

  8. 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( ...

  9. Codeforces Round #334(div.2) A

    A. Uncowed Forces time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. 实例源码--Android智能家居系统源码

      下载源码   技术要点:  1.Android应 用开发基础框架 2.SQLITE数据库的 使用 3.网络通信 4.GOOGLE地图模块 5.源码带有非常详 细的中文注释 ...... 详细介绍: ...

  2. Moving From Objective-C to C++

    1. virtual method or not: It's better to declare all cpp member methods without "virtual" ...

  3. Android_Intent_data_type

    layout.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x ...

  4. [记录]使用setTimeout实现不同时间进行切换文本的颜色

    开始使用的是setinterval(),但是setinterval()的time是固定的,假如我想改变time,就需要每次clearInterval()一次. 如: setInterval(funct ...

  5. highcharts 去掉右下角链接

    去掉右下角的highcharts.com链接需要加入以下代码: credits: { enabled:false }, 如果不设置,那么默认为显示.

  6. QQ粘性效果

    演示如下 QQ粘性效果.zip

  7. Extjs combo赋值与刷新的先后顺序

    今天在跟一个弹出框中的多选下拉框赋值并实现反选的时候.惊讶的发现:原来我之前对于Combo的赋值的认知观是错误的. 我开始在窗体的beforeshow事件中对Combo控件赋值.开始使用了setVal ...

  8. 转:『代码』JS封装 Ajax级联下拉列表

    在博客园看到一篇不错的AJAX级联下拉列表,觉得不错,特地拿下来 :转载来自:『大雪无痕』 ,原文地址 //当一个 下拉列表 改变时,触发所有联动:(警告:各下拉列表之间 请不要出现 循环依赖) // ...

  9. WCF编程系列(一)初识WCF

    WCF编程系列(一)初识WCF   Windows Communication Foundation(WCF)是微软为构建面向服务的应用程序所提供的统一编程模型.WCF的基本概念:  地址:定义服务的 ...

  10. eclipse下的tomcat内存设置大小

    在eclipse中设置,居然可以了, 设置步骤如下: 1.点击eclipse上的debug图标旁边的下拉箭头 2.然后选择Run Configurations, 3.系统弹出设置tomcat配置页面, ...