ACdream 1112
Alice and Bob
Time Limit: 6000/3000MS (Java/Others)Memory Limit: 256000/128000KB (Java/Others)SubmitStatisticNext ProblemProblem 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?
Input
This problem contains multiple test cases. The first line contains one number n(1 <= n <= 100000).
The second line contains n numbers.
All the numbers are positive and less than of equal to 5000000.
Output
For each test case, if Alice can win, output “Alice”, otherwise output “Bob”.
Sample Input
2
2 2
3
2 2 4Sample Output
Bob
AliceSource
yehuijieManager
/*************************************************************************
> File Name: 1112.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年09月05日 星期五 11时35分09秒
> Propose:
************************************************************************/
#include <set>
#include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int MAX_N = ;
int n, pnum, p[MAX_N], mindiv[MAX_N], cnt[MAX_N];
bool vis[MAX_N]; //线性筛,可以很方便的保存每个数最小的质因子,
//和每个数不同质因子的个数
void get_prime(int n) {
pnum = ; vis[] = true; cnt[] = ;
for (int i = ; i <= n; i++) {
if (!vis[i]) {
p[pnum++] = i; mindiv[i] = i; cnt[i] = ;
}
for (int j = ; j < pnum; j++) {
if (p[j] * i > n) break;
vis[p[j] * i] = true;
mindiv[p[j] * i] = p[j];
cnt[p[j] * i] = cnt[i] + ;
if (i % p[j] == ) break;
}
}
} //记忆化搜索所用数组,初始化为-1
int sg[];
int dfs(int n) {
if (sg[n] != -) return sg[n]; set<int> S;
//第一种转移变为因子a
for (int i = ; i < n; i++) S.insert(dfs(i));
//第二种转移变为两个因子a * b
for (int i = ; i < n; i++) S.insert(dfs(i)^dfs(n - i)); int g = ;
while (S.find(g) != S.end()) g++;
return sg[n] = g;
} void get_SG() {
get_prime(); memset(sg, -, sizeof(sg));
sg[] = ;
for (int i = ; i <= ; i++) {
sg[i] = dfs(i);
}
} int main(void) {
get_SG(); //预处理sg值
int n;
while (~scanf("%d", &n)) {
int ans = ;
for (int i = ; i < n; i++) {
int x;
scanf("%d", &x);
ans ^= sg[cnt[x]];
}
if (ans) puts("Alice");
else puts("Bob");
}
return ;
}
ACdream 1112的更多相关文章
- 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先,问谁能赢 思路 ...
- ACdream 1112 Alice and Bob (博弈&&素数筛选优化)
题目链接:传送门 游戏规则: 没次能够将一堆分成两堆 x = a*b (a!=1&&b!=1)x为原来堆的个数,a,b为新堆的个数. 也能够将原来的堆的个数变成原来堆的约数y.y!=x ...
- ACdream群赛1112(Alice and Bob)
题意:http://acdream.info/problem?pid=1112 Problem Description Here is Alice and Bob again ! Alice and ...
- Entity Framework 6 Recipes 2nd Edition(11-12)译 -> 定义内置函数
11-12. 定义内置函数 问题 想要定义一个在eSQL 和LINQ 查询里使用的内置函数. 解决方案 我们要在数据库中使用IsNull 函数,但是EF没有为eSQL 或LINQ发布这个函数. 假设我 ...
- BZOJ 1112: [POI2008]砖块Klo
1112: [POI2008]砖块Klo Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1736 Solved: 606[Submit][Statu ...
- ACdream 1214---矩阵连乘
ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...
- acdream.LCM Challenge(数学推导)
LCM Challenge Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit ...
- acdream.Triangles(数学推导)
Triangles Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit Stat ...
随机推荐
- Java虚拟机笔记
Java内存区域划分 1.程序计数器 线程私有,当前线程执行的行号指示器,指向当前线程执行的虚拟机字节码地址,线程的恢复,跳转等都需要用到它 2.Java虚拟机栈 线程私有,虚拟机栈描述的是Java内 ...
- SQL数据表纵横转换
SELECT DISTINCT '(select b.risk from rhwl_easy_genes_new_risk b where b.genes_id=a.id and b.disease= ...
- 【9.14NOIP模拟pj】wtaxi 题解——搜索
[9.14NOIP模拟pj]wtaxi 题目简化 有K辆车,N个人,上车给D元,只有S分钟.上车后无论多少人都要给D元,原地等多少分钟就没了多少元.求最小花费的钱. 我的思路 毫无疑问,此题可以用搜索 ...
- div contenteditable 重新编辑时focus光标定位到前面问题解决
<div class="editdiv" id="edit" contenteditable="true">这是添加文字< ...
- css之height: 100%的有效场景
在css的日常应用中,经常会遇到想要通过 height: 100%来达到使子盒子与父盒子高度一样的目的,但是偶尔明明设置了height: 100%,但是却没有达到想要的结果,这次我们就一起探索一下,什 ...
- 容斥原理——hdu1796
/* 遇到这种题一般用dfs,枚举起点来做 但是本题如何进行容斥? 比如以x为起点,第一步dfs到y,那么因子有lcm(x,y)的 所有数要被减掉(容斥中偶数是减法) 然后第二步dfs到z,那么因子有 ...
- 一个windows 两个jar
设置两个子JAVA_HOME,一个总设置两个子JAVA_HOME:JAVA_HOME6 = C:\Program Files\Java\jdk1.6.0_43JAVA_HOME8 = C:\Progr ...
- PHP如何打造一个高可用高性能的网站呢?
https://blog.csdn.net/jwq101666/article/details/80162245 1. 说到高可用的话要提一下redis,用过的都知道redis是一个具备数据库特征的n ...
- 服务安全-JWT(JSON Web Tokens):百科
ylbtech-服务安全-JWT(JSON Web Tokens):百科 JSON Web Tokens是一种开放的行业标准 RFC 7519方法,用于在双方之间安全地表示索赔. JWT.IO允许您解 ...
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...