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 ...
随机推荐
- (asp.net MVC学习)System.Web.Mvc.HtmlHelper学习及使用
在ASP.NET MVC框架中没有了自己的控件,页面显示完全就回到了写html代码的年代.还好在asp.net mvc框架中也有自带的HtmlHelper和UrlHelper两个帮助类.另外在MvcC ...
- knockout computed实例
function Privilege(options) { var self = this; self.fieldId = options.fieldId; self.readAccessType = ...
- SQL Server 数据库状态选项
选项 1. single_user(单用户),multi_user(多用户),restricted_user(受限用户); 描述数据库的用户访问属性,它们互斥,设置其中任何一个选项就会取消对其它选项的 ...
- ubuntu常用命令(转)
1.打开终端的方法 Ubuntu 中按左侧栏的第一个“面板主页(Dash 主页)”(可以按win键调出),在里面输入terminal可以打开终端,另外打开终端的快捷键是Ctrl+Alt+T 2.修改用 ...
- Android技术宅:自制USB OTG数据线
作为一名Android技术宅,USB OTG是你必须了解的,所谓USB OTG就是你可以利用手机或平板上用来充电.与电脑传输数据的micro USB接口来连接其他USB外设,如游戏手柄.鼠标.键盘.U ...
- sql 多条件查询 拼接字符串 改成 普通查询格式
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROC [dbo].[usp_SRV_CheckServiceDemandOrder] ) = ...
- CSS实现页面背景自动切换功能
From here:http://xiaomiya.iteye.com/blog/2047728 请看效果图: 完整代码如下: <!DOCTYPE HTML> <html> & ...
- 网易云课堂_程序设计入门-C语言_第七周:指针与字符串_2GPS数据处理
2 GPS数据处理(6分) 题目内容: NMEA-0183协议是为了在不同的GPS(全球定位系统)导航设备中建立统一的BTCM(海事无线电技术委员会)标准,由美国国家海洋电子协会(NMEA-The N ...
- leftpad填充函数;
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 复习day12-23
获取请求中的内容: request.getParameter(); get方式因为在地址栏所以需要转码: String name = new String(req.getparameter().get ...