题目链接

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. SQLServer 2008 还原数据库备份版本不兼容的问题

    我们准备还原一个数据库备份的时候,经常会弹出这样的错误:System.Data.SqlClient.SqlError: 该数据库是在运行版本 10.50.1600 的服务器上备份的.该版本与此服务器( ...

  2. Bootstrap Paginator分页插件(mark)

    Bootstrap Paginator分页插件

  3. Android开发 ShapeDrawable详解

    前言 ShapeDrawable一开始我以为它是对应xml文件属性里的shape的画图,后来发现我错了... 其实ShapeDrawable更像是一共自由度更大跟偏向与实现draw()方法的一共图像绘 ...

  4. Georgia and Bob

    Georgia and Bob 给出一个严格递增的正整数数列\(\{a_i\}\),每一次操作可以对于其中任意一个数减去一个正整数,但仍然要保证数列的严格递增性,现在两名玩家轮流操作,不能操作的玩家判 ...

  5. jQuery实现contains方法不区分大小写的方法教程

    jQuery.expr[':'].Contains = function(a, i, m){ return jQuery(a).text().toUpperCase() .indexOf(m[3].t ...

  6. vue之vant组件下拉加载更多

    vant地址:https://youzan.github.io/vant/#/zh-CN/intro 基础用法 List 组件通过loading和finished两个变量控制加载状态,当组件滚动到底部 ...

  7. 关于promise的用法

    promise是一个对象,里面保存着某个未来才会结束的事件,通常是一个异步事件. promise对象的两个特点: 1.对象的状态不受外界影响:pending(进行中) fulfilled(已成功) r ...

  8. android 头像选择以及裁剪

    一.布局申明 <ImageView android:id="@+id/head_image" android:layout_width="80dp" an ...

  9. JavaEE三层架构

    三层架构         三层架构是javaee规范中的推荐架构,传统意义上是分为表示层(UI).业务逻辑层(BLL).数据访问层(DAL).在javaee的开发中,三层架构具体分为表示层(web层) ...

  10. <每日一题>题目17:super()继承相关的面试题

    class A(object): def go(self): print("go A go!") def stop(self): print("stop A stop!& ...