题意: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)的更多相关文章

  1. ACdream 1112 Alice and Bob(素筛+博弈SG函数)

    Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit ...

  2. ACdream 1112 Alice and Bob (sg函数的变形+素数筛)

    题意:有N个数,Alice 和 Bob 轮流对这些数进行操作,若一个数 n=a*b且a>1,b>1,可以将该数变成 a 和 b 两个数: 或者可以减少为a或b,Alice先,问谁能赢 思路 ...

  3. 位运算 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 ...

  4. ACdream 1112 Alice and Bob (博弈&amp;&amp;素数筛选优化)

    题目链接:传送门 游戏规则: 没次能够将一堆分成两堆 x = a*b (a!=1&&b!=1)x为原来堆的个数,a,b为新堆的个数. 也能够将原来的堆的个数变成原来堆的约数y.y!=x ...

  5. 省赛13 Alice and Bob(二进制,找规律)

    题意:多项式相乘,(a0x+1)(a1x^2+1)(a2x^4+1),问x的m次方的系数是多少,当时没做出来,搜的某大神的博客,好理解. 思路:多列几个式子就能明白规律了: (a0x+1)(a1x^2 ...

  6. dp --- acdream原创群赛(16) --- B - Apple

    <传送门> B - Apple Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...

  7. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. bzoj4730: Alice和Bob又在玩游戏

    Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...

  9. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

随机推荐

  1. jquery.validate的效验方式

    jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 原文地址:http://www.cnblogs.c ...

  2. elasticsearch 索引 类型 id

    zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat logstash_indexer01.conf  input {         redi ...

  3. CC++初学者编程教程(12) 基于rhel6.3的Oracle数据库学习环境搭建

    前言 安装oracle 11g系统最好是1G以上内存,硬盘至少需要4.5G空间. 至少环境在Linux Server release 5.3以上. win安装包 win32_11gR2_databas ...

  4. aix installp软件包管理工具

    软件可以安装成两种状态:applied和committed.Applied状态保存了原来以前版本的软件,它把以前版本存储在/usr/lpp/PackageName目录下.这种方式可以回滚到以前的软件版 ...

  5. AndroidUI 引导页面的使用

    一个应用程序都少不了欢迎页面和引导页面,本文主要讲如何制作一个引页面: 首页所有的目录结构: 新建Welcome引导页面和Activity: <RelativeLayout xmlns:andr ...

  6. maven项目打包

    配置 你的pom.xml文件,配置 packaging为 war ,然后点击 pom.xml右键,run as 选择 install 或是 package: 如果项目没问题,配置没问题,就会在项目的t ...

  7. wx.ToolBar

    wx.ToolBar A toolbar is a bar of buttons and/or other controls usually placed below the menu bar in ...

  8. 使用扩展名获取mimetype

    在Android中很多时候我们需要计算出文件的mimetype,而我们通常的思路就是通过扩展名来获取对应的mimetype,而如果自行处理,将维护一个比较大的映射表,而实际上大可不必,Android提 ...

  9. 两种Makefile

    .PHONY:clean CC=g++ CFLAGS=-Wall -g BIN=test_queue OBJS=Queue.o test_main.o $(BIN):$(OBJS) $(CC) $(C ...

  10. C#核编之System.Environment类

    在前面的例子中用来了Environment.GetCommandLineArgs()这个方法,这个方法就是获取用户的命令行输入,是Environment类的方法之一,该方法的返回值是string[]  ...