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

每个子游戏的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. 支持jsonP的Controller写法

    支持jsonP的Controller写法 package com.taotao.sso.controller; import org.apache.commons.lang3.StringUtils; ...

  2. Small things are better

    Yesterday I had fun time repairing 1.5Tb ext3 partition, containing many millions of files. Of cours ...

  3. mysql修改表中某个字段的默认值

    Mysql中用SQL增加.删除字段,修改字段名.字段类型.注释,调整字段顺序总结   在网站重构中,通常会进行数据结构的修改,所以添加,删除,增加mysql表的字段是难免的,有时为了方便,还会增加修改 ...

  4. 怎样在WPS上实现代码语法高亮

    转载自:http://www.cnblogs.com/yuphone/archive/2009/12/13/1622901.html 小時不識月 Stupid & Hungry 本文列举两种可 ...

  5. MyBatis的SQL语句映射文件详解

    SQL 映射XML 文件是所有sql语句放置的地方.需要定义一个workspace,一般定义为对应的接口类的路径.写好SQL语句映射文件后,需要在MyBAtis配置文件mappers标签中引用 < ...

  6. bzoj1420/1319 Discrete Root

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1420 http://www.lydsy.com/JudgeOnline/problem.ph ...

  7. 我喜欢的4个VS扩展吧

    原文发布时间为:2011-06-09 -- 来源于本人的百度文章 [由搬家工具导入]

  8. bzoj 2668 费用流

    我们可以把初始状态转化为目标状态这一约束转化为将黑子移动到目标状态所需要的最少步数. 除了初始点和目标点之外,剩下的点如果被经过那么就会被交换两次,所以我们将一个点拆成3个点,a,b,c,新建附加源点 ...

  9. python configparse

    # 参考:https://www.cnblogs.com/lily1989/p/8401005.html # https://blog.csdn.net/willhuo/article/details ...

  10. How to learn wxPython

    目录 How to learn wxPython Learn Python Choose a good editor Install wxPython Read the wxPython tutori ...