【博弈论】【SG函数】Codeforces Round #188 (Div. 1) D. Game with Powers
将整个游戏可以划分成若干个互不相交的子游戏。
每个子游戏的sg值只与其中的数的个数有关。而这个数不会超过30。
于是可以预处理出这个sg值表。
然后从1到n枚举,对<=sqrt(n)的部分,用个set判重。
对于大于sqrt(n)的部分,统计其中不包含在之前已经划分出来的子游戏内的数的个数,如果是奇数,就再异或上1。
/*
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
using namespace std;
map<int,int>SG;
int N,n;
int sg(int x)
{
if(SG.find(x)!=SG.end())
return SG[x];
set<int>S;
for(int i=1;i<=N;++i)
if((x>>(i-1))&1)
{
int t=x;
for(int j=i;j<=N;j+=i)
if((x>>(j-1))&1)
t^=(1<<(j-1));
S.insert(sg(t));
}
for(int i=0;;++i)
if(S.find(i)==S.end())
return SG[x]=i;
}
int main()
{
freopen("test.txt","w",stdout);
scanf("%d",&n);
for(N=1;N<=n;++N)
{
SG.clear();
printf("SG[%d]=%d\n",N,sg((1<<N)-1));
}
return 0;
}
*/
#include<cstdio>
using namespace std;
typedef long long ll;
bool vis[1000001];
int SG[111],n,ans;
int main()
{
SG[1]=1;
SG[2]=2;
SG[3]=1;
SG[4]=4;
SG[5]=3;
SG[6]=2;
SG[7]=1;
SG[8]=5;
SG[9]=6;
SG[10]=2;
SG[11]=1;
SG[12]=8;
SG[13]=7;
SG[14]=5;
SG[15]=9;
SG[16]=8;
SG[17]=7;
SG[18]=3;
SG[19]=4;
SG[20]=7;
SG[21]=4;
SG[22]=2;
SG[23]=1;
SG[24]=10;
SG[25]=9;
SG[26]=3;
SG[27]=6;
SG[28]=11;
SG[29]=12;
SG[30]=14;
scanf("%d",&n);
ans^=1;
int all=0;
for(ll i=2ll;i*i<=(ll)n;++i)
{
if(!vis[i])
{
int cnt=0;
for(ll j=(ll)i;j<=(ll)n;j*=(ll)i)
{
if(j*j<=(ll)n)
vis[j]=1;
++cnt;
++all;
}
ans^=SG[cnt];
}
}
ans^=((n-all-1)&1);
puts(ans ? "Vasya" : "Petya");
return 0;
}
【博弈论】【SG函数】Codeforces Round #188 (Div. 1) D. Game with Powers的更多相关文章
- Codeforces Round #486 (Div. 3) D. Points and Powers of Two
Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...
- Codeforces Round #188 (Div. 1) B. Ants 暴力
B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...
- Codeforces Round #188 (Div. 2) C. Perfect Pair 数学
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...
- Codeforces Round #188 (Div. 2) B. Strings of Power 水题
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...
- Codeforces Round #188 (Div. 2) A. Even Odds 水题
A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...
- Codeforces Round #188 (Div. 1 + Div. 2)
A. Even Odds 奇数个数\(\lfloor \frac{n+1}{2}\rfloor\) B. Strings of Power 从位置0开始,统计heavy个数,若当前为metal,则可以 ...
- Codeforces Round #486 (Div. 3)988D. Points and Powers of Two
传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...
- Codeforces Round #721 (Div. 2)A. And Then There Were K(位运算,二进制) B1. Palindrome Game (easy version)(博弈论)
半个月没看cf 手生了很多(手动大哭) Problem - A - Codeforces 题意 给定数字n, 求出最大数字k, 使得 n & (n−1) & (n−2) & ...
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
随机推荐
- fail2ban软件 +ssh密钥登录
fail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是调用防火墙屏蔽),如:当有人在试探你的SSH.SMTP.FTP密码,只要达到你预设的次数,fa ...
- Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)
D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的 ...
- 在linux环境下让java代码生效的步骤
1.kill jboss 2.compile 3.deploy 4.bootstrap jboss.
- 使用T4模板生成MySql数据库实体类
注:本文系作者原创,但可随意转载. 现在呆的公司使用的数据库几乎都是MySQL.编程方式DatabaseFirst.即先写数据库设计,表设计按照规范好的文档写进EXCEL里,然后用公司的宏,生成建表脚 ...
- Java多线程-一个简单的线程,实现挂起和恢复的功能
public class MySprite implements Runnable { /* * 线程用变量 */ private boolean running = false; private b ...
- 模拟实现jdk动态代理
实现步骤 1.生成代理类的源代码 2.将源代码保存到磁盘 3.使用JavaCompiler编译源代码生成.class字节码文件 4.使用JavaCompiler编译源代码生成.class字节码文件 5 ...
- BigDecimal精度问题
介绍 1.商业计算使用BigDecimal. 2.使用参数为String的构造函数. 3.BigDecimal都是不可变的,每一步的运算时,都会产生一个新的对象.所以在做加减乘除后千万要保存操作后的值 ...
- PCIe 中的Capability 结构的寻址
PCI-X 和PCIe 总线规范要求其设备必须支持Capabilities 结构.在PCI 总线的基本配置空间中,包含一个Capabilities Pointer 寄存器,该寄存器存放Capabili ...
- 用python写爬虫笔记(一)
https://bitbucket.org/wswp/code http://example.webscraping.com http://www.w3schools.com selenium.g ...
- 【转】java中的集合和数组
转载自:http://www.cnblogs.com/summers/p/4094260.html 数组Array和集合的区别: (1)数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型 ...