ACdream群赛1112(Alice and Bob)
题意:http://acdream.info/problem?pid=1112
Problem Description
Here is Alice and Bob again !
Alice and Bob are playing a game. There are several numbers.First, Alice choose a number n.Then he can replace n (n > 1)with one of its positive factor but not itself or he can replace n with a and b.Here a*b =
n and a > 1 and b > 1.For example, Alice can replace 6 with 2 or 3 or (2, 3).But he can’t replace 6 with 6 or (1, 6). But you can replace 6 with 1. After Alice’s turn, it’s Bob’s
turn.Alice and Bob take turns to do so.Who can’t do any replace lose the game.
Alice and Bob are both clever enough. Who is the winner?
解法:非常好的博弈题。关键是找准每一个数的状态。每一个数的状态是每一个数的分解后的质数的个数。然后就是获得每一个数的状态号能够做到On,就是线性筛素数时候顺便将每一个数的最小的质数因子筛出来,从小大大先预处理,然后求F(n)就等于F(n/least[n])+1。获得状态号,sg部分就不多说了。
代码:
/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
//freopen ("in.txt" , "r" , stdin);
using namespace std; #define eps 1e-8
#define zero(_) (abs(_)<=eps)
const double pi=acos(-1.0);
typedef long long LL;
const int Max=5000010;
const int INF=1000000007; int f[300];
bool rem[Max];
int out[Max];
int least[Max];
int p=0;
void init()
{
for(int i=2; i<Max; i++)
if(!rem[i])
{
for(int j=i*2; j<Max; j+=i)
{
if(least[j]==-1)
least[j]=i;
rem[j]=1;
}
least[i]=i;
}
}
int getans(int t)
{
if(f[t]!=-1)
return f[t];
int Rem[1000];
memset(Rem,0,sizeof Rem);
Rem[0]=1;
for(int i=1; i<=t/2; i++)
{
Rem[getans(i)]=1;
Rem[getans(t-i)]=1;
Rem[getans(t-i)^getans(i)]=1;
}
int to=0;
while(Rem[to])to++;
return f[t]=to;
}
int F(int n)
{
if(out[n]!=-1)
return out[n];
int ans=F(n/least[n])+1;
return out[n]=ans;
}
int main()
{
int n;
memset(f,-1,sizeof f);
memset(out,-1,sizeof out);
memset(least,-1,sizeof least);
f[1]=1;
init();
out[1]=0;
for(int i=0; i<20; i++)
F(1<<i);// cout<<i<<" "<<getans(i)<<endl;
while(scanf("%d",&n)==1)
{
int ans=0;
for(int i=0; i<n; i++)
{
int t;
scanf("%d",&t);
ans^=getans(F(t));
}
if(ans)
puts("Alice");
else
puts("Bob");
}
return 0;
}
ACdream群赛1112(Alice and Bob)的更多相关文章
- ACdream 1112 Alice and Bob(素筛+博弈SG函数)
Alice and Bob Time Limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit ...
- ACdream 1112 Alice and Bob (sg函数的变形+素数筛)
题意:有N个数,Alice 和 Bob 轮流对这些数进行操作,若一个数 n=a*b且a>1,b>1,可以将该数变成 a 和 b 两个数: 或者可以减少为a或b,Alice先,问谁能赢 思路 ...
- 位运算 2013年山东省赛 F Alice and Bob
题目传送门 /* 题意: 求(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1) 式子中,x的p次方的系数 二进制位运算:p ...
- ACdream 1112 Alice and Bob (博弈&&素数筛选优化)
题目链接:传送门 游戏规则: 没次能够将一堆分成两堆 x = a*b (a!=1&&b!=1)x为原来堆的个数,a,b为新堆的个数. 也能够将原来的堆的个数变成原来堆的约数y.y!=x ...
- 省赛13 Alice and Bob(二进制,找规律)
题意:多项式相乘,(a0x+1)(a1x^2+1)(a2x^4+1),问x的m次方的系数是多少,当时没做出来,搜的某大神的博客,好理解. 思路:多列几个式子就能明白规律了: (a0x+1)(a1x^2 ...
- dp --- acdream原创群赛(16) --- B - Apple
<传送门> B - Apple Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- bzoj4730: Alice和Bob又在玩游戏
Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
随机推荐
- Ubuntu root登陆
分两步: 1.激活root 输入命令:sudo passwd,键入当前用户密码之后,为系统设置root密码:交互如下: jack@ubuntu:~$ sudo passwd[sudo] passwor ...
- python 自定义信号处理器
说明: 这里所说的信号与kill 命令中的信号指的是同一个. #!/usr/bin/python #!coding:utf-8 import sys,time,signal def now(): re ...
- PostgreSql入门命令
1 命令行登录数据库 有两种方式,一是直接在系统shell下执行psql命令:而是先进入psql环境,然后再连接数据库.下面分别给出实例: (1)直接登录 执行命令:psql -h 192.168.1 ...
- JQeury Image LazyLoad
使用jquery插件实现图片延迟加载技术 http://www.cnblogs.com/szytwo/archive/2012/12/27/2836141.html EasyUI http://www ...
- php快递查询
http://www.oschina.net/code/snippet_60100_25087 <?php class Express { private $expressname =array ...
- CC++初学者编程教程(7) 搭建Windows EclipseCCPP软件开发环境
1根据电脑是32位还是64位来选择工具 2 查看电脑是64位 3 管理员身份运行这个文件 4 安装JDK64位 5. 下一步 6 开始安装 7 安装JAVA 8 安装进行时 9 安装成功 10解压缩 ...
- 自己主动更新--下载apk以及提示对话框的实现(3)
下载apk以及提示对话框的实现 一.步骤: 1. 确定有能够更新的版本号,对话框提醒用户是否进行更新. 2. 选择更新的话,显示下载对话框而且进行下载.否则关闭提示更新对话框. 3. Apk下载完毕后 ...
- UVA - 10098 - Generating Fast (枚举排列)
思路:生成全排列,用next_permutation.注意生成之前先对那个字符数组排序. AC代码: #include <cstdio> #include <cstring> ...
- ODBC与JDBC比較
在学习J2EE的JDBC过程中,刚见到JDBC就立即联想到了ODBC,并且我们能够肯定他们之间有必定的关系.開始学它的时候还是认为有点晕,于是就查了非常多资料,与比較熟悉的ODBC进行了比較. 先各自 ...
- js——BOM
BOM:Browser Object Model 浏览器对象模型 open(页面的地址url,打开的方式) :方法 打开一个新的窗口(页面) 如果url为空,折磨人打开一个空白页面 如果打开方式为 ...