题意:

有1~n,n个数字,两个人轮流操作,每一次一个人可以拿一个数字$x$,之后$x, x^2, x^3....x^t$全都被删掉。

给定n,问最优策略下谁赢。

解法:

考虑SG函数,可以注意到题目中取走$x$后,$x^2,x^3...$不可以取,类似石子合并问题。

对于1~n的数字可以分为两类:

  1.不存在$x^t, t>1$,可以视为一堆只有一块石头的石子堆,$SG(1) = 0$。

  2.存在$x^t, t>1$。

对于第一种情况,直接记录有多少个x满足条件即可,分奇偶讨论。

对于第二种情况,显然有$t<=30$,可以注意到最终$SG$值和$x$无关,这样打表预处理$sg(t)$表示$x^1,x^2...x^t$

对应的$SG$值,打表直接用$O(2^30)$状压即可(注意到$sg(t)<=30$,所以用char类型的sg数组即可节省空间)。

实际上有效的状态并不多,所以只要几秒钟(意外的快)。

最后求NIM和即可。

总效率$O(\sqrt{n}*logn)$

 #include <iostream>
#include <cstdio>
#include <cstring> #define N 1000010
#define LL long long using namespace std; bool flag[N];
int n;
int SG[]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,}; int main()
{
scanf("%d",&n);
int sum=n;
int ans=;
for(LL i=;i*i<=n;i++)
{
if(flag[i]) continue;
int tmp=;
for(LL x=i;x<=n;x*=i)
{
if(x*x<=n) flag[x]=;
tmp++;
}
ans^=SG[tmp];
sum-=tmp;
}
ans ^= sum&;
if(ans==) puts("Petya");
else puts("Vasya");
return ;
}

Game with Powers的更多相关文章

  1. CodeForces 404C Ivan and Powers of Two

    Ivan and Powers of Two Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & % ...

  2. Educational Codeforces Round 15 Powers of Two

    Powers of Two 题意: 让求ai+aj=2的x次幂的数有几对,且i < j. 题解: 首先要知道,排完序对答案是没有影响的,比如样例7 1一对,和1 7一对是样的,所以就可以排序之后 ...

  3. Educational Codeforces Round 7 F - The Sum of the k-th Powers 拉格朗日插值

    The Sum of the k-th Powers There are well-known formulas: , , . Also mathematicians found similar fo ...

  4. cf702B Powers of Two

    B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  5. (Problem 29)Distinct powers

    Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...

  6. UVA 10622 - Perfect P-th Powers(数论)

    UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...

  7. UVALive 6472 Powers of Pascal

    标题手段: 他给了一个无限Pascal阵,定义了powers,然后询问power为P的pascal矩阵里面的第R行C列的元素是多少. 最開始读错题意了...然后 就成了一个神得不得了的题了.后来请教的 ...

  8. Educational Codeforces Round 15_B. Powers of Two

    B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  9. The Super Powers

    The Super Powers Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Subm ...

  10. Perfect Pth Powers poj1730

    Perfect Pth Powers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16383   Accepted: 37 ...

随机推荐

  1. MEMS--微机电系统

    http://baike.baidu.com/view/95221.htm?fromtitle=MEMS&fromid=686299&type=search 微机电系统 编辑   您检 ...

  2. JAVA RMI远程方法调用简单实例(转载)

    来源:http://www.cnblogs.com/leslies2/archive/2011/05/20/2051844.html RMI的概念 RMI(Remote Method Invocati ...

  3. 网络爬虫(蜘蛛)Scrapy,Python安装!

    Scrapy,Python安装.使用! 1.下载安装Python2.7.6.由于Scrapy还不支持3.x版本号. Latest Python 2 Release - Python 2.7.6,安装时 ...

  4. Nmap扫描教程之基础扫描具体解释

    Nmap扫描教程之基础扫描具体解释 Nmap扫描基础扫描 当用户对Nmap工具了解后,就可以使用该工具实施扫描.通过上一章的介绍,用户可知Nmap工具能够分别对主机.port.版本号.操作系统等实施扫 ...

  5. 计算IMEI号的校验位

    计算IMEI号的校验位 移动设备国际识别码(IMEI:International Mobile Equipment Identification Number)是差别移动设备的标志,具有唯一性,贴在手 ...

  6. php 批量删除数据

    php 批量删除数据 :比如我们在看邮箱文件的时候,积攒了一段时间以后,看到有些文件没有用了 这时候我们就会想到把这些 没用的文件删除,这时候就用到了批量删除数据的功能,这里我是用了数据库原有的一个表 ...

  7. 解决用EasyDarwin开源流媒体服务器做HLS直播时Flash Player卡住的问题

    最近在开发EasyDarwin开源流媒体服务器HLS直播的时候发现一个现象:在PC上用flash player播放HLS和在ios上面播放HLS时,效果明显不同,在ios上播放非常稳定,而在flash ...

  8. Netty 仿QQ聊天室 (实战二)

    Netty 聊天器(百万级流量实战二):仿QQ客户端 疯狂创客圈 Java 分布式聊天室[ 亿级流量]实战系列之15 [博客园 总入口 ] 源码IDEA工程获取链接:Java 聊天室 实战 源码 写在 ...

  9. Part of defining a topology is specifying for each bolt which streams it should receive as input

    http://storm.apache.org/ [doing for realtime processing what Hadoop did for batch processing ] Apach ...

  10. 使用Swift开发iOS项目、UI创建、方法调用

    //1.root控制器的创建        var rootCtrl =RootViewController()        var root:UINavigationController =UIN ...