将整个游戏可以划分成若干个互不相交的子游戏。

每个子游戏的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的更多相关文章

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

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

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

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

  5. 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/ ...

  6. Codeforces Round #188 (Div. 1 + Div. 2)

    A. Even Odds 奇数个数\(\lfloor \frac{n+1}{2}\rfloor\) B. Strings of Power 从位置0开始,统计heavy个数,若当前为metal,则可以 ...

  7. Codeforces Round #486 (Div. 3)988D. Points and Powers of Two

    传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...

  8. 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) & ...

  9. Codeforces Round #184 (Div. 2) E. Playing with String(博弈)

    题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...

随机推荐

  1. Ubuntu系统iptables规则的查看和清除

    系统不支持service iptables restart,service iptables status,如何查看与清除iptable的规则呢? 一 iptables查看基本语法 iptables ...

  2. 批量添加公钥给server的bash

    Bash 脚本 #/bin/bash adduser vlmonitor mkdir -p /home/vlmonitor/.ssh chown -R vlmonitor.vlmonitor /hom ...

  3. Spring学习--引用其他Bean , 内部Bean

    引用其他Bean: 组成应用程序的 Bean 经常需要相互协作以完成应用程序的功能 , 要使 Bean 能够相互访问, 就必须在 Bean 配置文件中指定对 Bean 的引用. 在 Bean 的配置文 ...

  4. 使用vue开发webApp,安卓手机自带回退键的问题解决

    首先,我先为大家说明,为什么我要写这篇随笔: 因为我们写的webapp,在安卓手机上,按一次回退键,就会退出app,回到桌面,而不是像原生app一样,会有一个提示,例如,“再按一次退出应用”的这种提示 ...

  5. MySql数据库学习总结(MySQL入门到精通)

    2017.1.24-2.3日(在大兴实验室) 1.数据库存储引擎: (1)MyISAM: 访问速度快,对事物完整性没要求,并以访问为主的适合这个 (2)InnoDB: 更占磁盘空间,需要进行频繁的更新 ...

  6. HDU 5878---预处理+二分查找

    给一个数n,让你求一个大于等于n的最小的满足题意中2^a*3^b*5^c*7^d的数字. 思路: #include<iostream> #include<cstdio> #in ...

  7. JVM 性能排查--汇总

    参考:http://blog.sina.com.cn/s/blog_61d758500102wnus.html

  8. AtCoder Regular Contest 082 F

    Problem Statement We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contai ...

  9. [BZOJ2190&BZOJ2705]欧拉函数应用两例

    欧拉函数phi[n]是表示1~n中与n互质的数个数. 可以用公式phi[n]=n*(1-1/p1)*(1-1/p2)*(1-1/p3)...*(1-1/pk)来表示.(p为n的质因子) 求phi[p] ...

  10. poj 2312 Battle City(优先队列+bfs)

    题目链接:http://poj.org/problem?id=2312 题目大意:给出一个n*m的矩阵,其中Y是起点,T是终点,B和E可以走,S和R不可以走,要注意的是走B需要2分钟,走E需要一分钟. ...