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 ...
随机推荐
- linux 如何禁用账号和解除禁用账号
把账号禁用可以有几个方法:1. # usermod -L <username> # usermod -U <username> // 解除禁用2. 修改/etc/passwd文 ...
- Linux系统针对网卡中断的优化处理
摘要: 中断: 当网卡接收到数据包后,会触发硬中断,通知CPU来收包.硬中断是一个CPU和网卡交互的过程.这其实会消耗CPU资源.特别是在使用速度极快的万兆网卡 之后,大量的网络交互使得CPU很大一部 ...
- Oracle EBS-SQL (BOM-9):检查系统BOM总数.sql
SELECT ITM.SEGMENT1 物料编码 ,ITM.DESCRIPTION 物料描述 ...
- [技巧]使用Xcode集成的HeaderDoc自动生成注释和开发文档
[技巧]使用Xcode集成的HeaderDoc自动生成注释和开发文档 Doxygen本来是一个很好的工具,可是我感觉在mac系统下,如果用doxygen最后生成的CHM文件感觉就不是那么恰当, ...
- Python学习笔记4-如何快速的学会一个Python的模块、方法、关键字
想要快速的学会一个Python的模块和方法,两个函数必须要知道,那就是dir()和help() dir():能够快速的以集合的型式列出该模块下的所有内容(类.常量.方法)例: #--encoding: ...
- C#.NET学习笔记2---C#.第一个C#程序
C#.NET学习笔记2---C#.第一个C#程序 技术qq交流群:JavaDream:251572072 教程下载,在线交流:创梦IT社区:www.credream.com 6.第一个C#程序: ...
- oracle10G之前介质下载地址【珍藏版】
今天在互联网搜了一下相关介质下载,自己记录一下. Oracle9i Database Release 2 Enterprise/Standard/Personal Edition for Window ...
- HNU 12850 Garage
长为H的格子里面放n个长为h的格子 最多会有n+1个空隙 要使每一个空隙长度都小于h (H-h*n)/(n+1)<h n>(H/h-1)/2 #include<bits/stdc++ ...
- sql2008中时间类型问题
DATEDIFF (DD ,@sdate ,getdate() ) eg30 计算从开始日期到今天的天数 datename(weekday,@sdate) eg星期三 查询那一天是星期几 SQL Se ...
- TCP/IP协议族
1.TCP(传输控制协议)/IP(网际协议)协议族是一个网络通讯模型,以及一整个网络传输协议家族,为互联网的基础通讯架构. TCP/IP四层协议的表示方法: 2.TCP/IP参考模型映射到OSI模型: ...