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 ...
随机推荐
- LuoguP3498 [POI2010]KOR-Beads
呀呀呀,临走10分钟刷一道水题 然而只是记一下第一次hash被卡 各种模数都被卡了... 本来想打双哈希了,后来皮了一下,模数改成了998244353,然后竟然A掉了 正着hash一遍,反着hash一 ...
- 【默默努力】fishingGame
这个捕鱼游戏挺有意思的,通过发射子弹,打鱼.打鱼的子弹会消耗金币,但是打鱼如果打到了鱼,就会奖励金币的数量. 我如果写这个的话,应该会画一个 背景海底,然后生成很多鱼的图片,还要有一个大炮,金币.大炮 ...
- 解决 no compatible version found: ionic-native@^3.5.0
npm ERR! Linux --generic npm ERR! argv "/usr/src/node-v6.10.3-linux-x64/bin/node" "/u ...
- springboot中activeMQ消息队列的引入与使用(发送短信)
1.引入pom依赖 <!--activemq--><dependency> <groupId>org.springframework.boot</groupI ...
- WCF加密操作(包括证书和证书+帐号密码)
WCF作为.net三大组件之一,伟大之处不用多说,但是其加密配置对于我这样的萌新来说还是颇有难度,因此将几天来的研究成果共享出来,与各位共勉~ 首先声明我的开发环境,Win10创意者更新 + Visu ...
- PAT甲级——A1003Emergency
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- Java(8)中List的遍历方式总结
本篇文章主要讲述了List这一集合类型在Java,包括Java8中的遍历方式,不包括其他的过滤,筛选等操作,这些操作将会在以后的文章中得到提现,由List可以类推到Set等类似集合的遍历方式. pub ...
- IO流11 --- 缓冲流(字符型)实现文本文件的复制 --- 技术搬运工(尚硅谷)
方法一:读到指定字符数组 @Test public void test7(){ BufferedReader br = null; BufferedWriter bw = null; try { br ...
- GitHub:如何构建一个股票市场知识图谱?(附代码&链接)
来源:专知 本文约 600007 董事⻓/董事 高燕 女 60 600007 执⾏董事 刘永政 男 50 600008 董事⻓/董事 ··· ··· ··· ··· ··· 注:建议表头最好用相应的英 ...
- BMP 图片格式
BMP根据颜色深度,可以分为2(1位).16(4位).256(8位).65536(16位)和1670万(24位)以及32位含有alpha通道.8位图像可以是 索引彩色图像外,也可以是灰阶图像,而索引 ...