题目链接

Alice and Bob

Time Limit: 6000/3000MS (Java/Others)Memory Limit: 256000/128000KB (Java/Others)

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?

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 4

Sample Output

Bob
Alice

Source

yehuijie

Manager

给出n个数,两个轮流任选一个数n进行操作,第一种操作是将该数变为他的一个因子,但是不能变为本身。
第二种是变成两个数a和b,要满足a * b = n。a>1, b>1.
第一次写线性筛,这个算法和普通的筛法略有不同,也更不好理解一点,就是说算法保证每个数只会被
他的最小的质因子筛去。也保证了算法的时间是线性的。
Accepted Code:
/*************************************************************************
> 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的更多相关文章

  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. ACdream 1112 Alice and Bob (博弈&amp;&amp;素数筛选优化)

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

  4. ACdream群赛1112(Alice and Bob)

    题意:http://acdream.info/problem?pid=1112 Problem Description Here  is Alice and Bob again ! Alice and ...

  5. Entity Framework 6 Recipes 2nd Edition(11-12)译 -> 定义内置函数

    11-12. 定义内置函数 问题 想要定义一个在eSQL 和LINQ 查询里使用的内置函数. 解决方案 我们要在数据库中使用IsNull 函数,但是EF没有为eSQL 或LINQ发布这个函数. 假设我 ...

  6. BZOJ 1112: [POI2008]砖块Klo

    1112: [POI2008]砖块Klo Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1736  Solved: 606[Submit][Statu ...

  7. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  8. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  9. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

随机推荐

  1. 跳过爱奇艺优酷vip

      1.google chrome浏览器  2.下载插件安装 Tampermonkey  https://pan.baidu.com/s/1qvRQD2UO6gPHogjtSUBwUw       将 ...

  2. [笔记]180612 for DevOps

    adb devices 识别不了安卓手机:我下的adb interface驱动下载链接:如果设备管理器中ADB Interface是黄色的,就需要先安装adb interface驱动(BD:adb i ...

  3. [转]成为Java顶尖程序员 ,看这11本书就够了

    “学习的最好途径就是看书“,这是我自己学习并且小有了一定的积累之后的第一体会.个人认为看书有两点好处: 1.能出版出来的书一定是经过反复的思考.雕琢和审核的,因此从专业性的角度来说,一本好书的价值远超 ...

  4. [转]MEF学习

    MEF学习 :http://www.cnblogs.com/comsokey/p/MEF1.html C#可扩展编程之MEF学习笔记(一):MEF简介及简单的Demo C#可扩展编程之MEF学习笔记( ...

  5. 五. Arrow Function 箭头函数

    箭头函数三大好处: 1. 简明的语法 举例: 如果只有一个参数,可以不加(),多个参数用 "," 隔开 2. 隐式返回 首先说下什么是显示返回,显示返回就是 return 加上你要 ...

  6. SQLite C++操作种

    SQLite C++操作类 为了方便SQLite的使用,封装了一个SQLite的C++类,同时支持ANSI 和UNICODE编码.代码如下:   头文件(SQLite.h) /************ ...

  7. iOS开发CATransform3D.h属性详解和方法使用

    1.CATransform3D简介 layer有个属性transform,是CATransform3D类型.可以使其在三维界面作平移.缩放和旋转单独或组合动画! CATransform3D结构体: / ...

  8. wpf布局控件总结

    首先要认识到wpf所有的布局控件都继承自Panel类,Panel类又继承自其他类.继承关系如下: 一.StackPanel布局面板 1.该面板在单行或者单列中以堆栈的形式放置其子元素. 默认情况下,S ...

  9. csp-s模拟测试b组加餐antipalindome,randomwalking,string题解

    题面:https://www.cnblogs.com/Juve/articles/11599318.html antipalindome: 打表找规律? 对于一个回文串,我们只要保证3位以内不回文即可 ...

  10. python登录aspx网站

    1.安装模块 2.准备aspx登录页面 3.示例代码 #coding:utf-8 import re from bs4 import BeautifulSoup import gzip import ...