codeforces 603C. Lieges of Legendre sg函数
n堆石子, 可以拿走一堆中的一颗, 或者将一堆数量为2*x的石子分为k堆x个的石子。k由题目给出。
k分奇偶讨论。 k为偶数时,k堆x个的石子异或结果为0; k为奇数时, k堆x个石子异或结果与mex(x)相等, 然后打不同的sg表找规律, 打表程序看代码。
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int sg[];
/*int mex1(int x) {
if(~sg[x])
return sg[x];
int vis[105];
mem(vis);
vis[mex1(x-1)] = 1;
if(x%2==0) //k为奇数
vis[mex1(x/2)] = 1;
for(int i = 0; ; i++)
if(!vis[i])
return sg[x] = i;
}
int mex2(int x) { //k为偶数
if(~sg[x])
return sg[x];
int vis[105];
mem(vis);
vis[mex2(x-1)] = 1;
if(x%2==0)
vis[0] = 1;
for(int i = 0; ; i++)
if(!vis[i])
return sg[i] = i;
}*/
int mex2(int x) {
if(x<=) {
return x;
}
if(x&)
return ;
return ;
}
int mex1(int x) {
if(x<=) {
if(x&)
return ;
if(x==)
return ;
return ;
}
if(x&)
return ;
int tmp = mex1(x/);
if(tmp==)
return ;
return ;
}
int main()
{
mem1(sg);
/*sg[0] = 0;
for(int i = 0; i<=100; i++)
sg[i] = mex1(i);
for(int i = 0; i<=100; i++) {
printf("[%d:%d]\n", i, sg[i]);
}*/
int n, k, x, ans = ;
cin>>n>>k;
while(n--) {
scanf("%d", &x);
if(k&)
ans ^= mex1(x);
else
ans ^= mex2(x);
}
if(!ans) {
puts("Nicky");
} else {
puts("Kevin");
}
return ;
}
codeforces 603C. Lieges of Legendre sg函数的更多相关文章
- 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 + ...
- Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)
D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...
- Educational Codeforces Round 68 (Rated for Div. 2)D(SG函数打表,找规律)
#include<bits/stdc++.h>using namespace std;int sg[1007];int main(){ int t; cin>>t; while ...
- CF# 334 Lieges of Legendre
C. Lieges of Legendre time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- 【转】博弈—SG函数
转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...
- HDU 1848 Fibonacci again and again【SG函数】
对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算 ...
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
随机推荐
- 网站图片列表动态显示、根据屏幕宽度动态设置DIV的CSS样式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Nutch的发展历程
Nutch的创始人是Doug Cutting,他同时也是Lucene.Hadoop和Avro开源项目的创始人 下面是Nutch的发展历程: 月由Doug Cutting发起,托管于Sourceforg ...
- Spring整合hibernate4:事务管理[转]
Spring和Hibernate整合后,通过Hibernate API进行数据库操作时发现每次都要opensession,close,beginTransaction,commit,这些都是重复的工作 ...
- Windows使用过程中的一些常见问题的解决方案
Win8安装程序出现2502.2503错误解决方法 参见百度经验帖子:http://jingyan.baidu.com/article/a501d80cec07daec630f5e18.html
- 《CSAPP》读书杂记 - Chapter 2. Representing and Manipulating Information
1. 一段查看地址内容的代码 代码: #include <stdio.h> typedef unsigned char *byte_pointer; void show_bytes(byt ...
- STL MAP 反序迭代
ITS_NOTICE_MAP::reverse_iterator it = noticeMap.rbegin(); for ( ; it != noticeMap.rend(); ++it ) { I ...
- 在linux中限制用户ftp访问权限
1.环境:redhat linux企业版4.ftp为vsftp.被限制用户名为aaa.被限制路径为/bbb.2.建用户:在root用户下,相继进行如下操作 adduser aaa ...
- java文本编辑器5
package peng_jun; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.* ...
- java实现发送短信
本程序是通过使用中国网建提供的SMS短信平台实现的(该平台目前为注册用户提供5条免费短信,3条免费彩信,这足够用于我们测试用了.在使用前需要注册,注册地址为http://sms.webchinese. ...
- J2SE知识点摘记(九)
1. 线程操作的一些方法 方法名称 方法说明 public static int activeCount() 返回线程组中目前活动的线 ...