Description

Alice and Bob are in their class doing drills on multiplication and division. They quickly get bored and instead decide to play a game they invented.

The game starts with a target integer N≥2N≥2 , and an integer M=1M=1. Alice and Bob take alternate turns. At each turn, the player chooses a prime divisor p of N, and multiply M by p. If the player’s move makes the value of M equal to the target N, the player wins. If M>NM>N , the game is a tie. Assuming that both players play optimally, who (if any) is going to win?

Input

The first line of input contains T(1≤T≤10000)T(1≤T≤10000) , the number of cases to follow. Each of the next T lines describe a case. Each case is specified by N(2≤N≤231−1)N(2≤N≤231−1) followed by the name of the player making the first turn. The name is either Alice or Bob.

Output

For each case, print the name of the winner (Alice or Bob) assuming optimal play, or tie if there is no winner.

Sample Input

10
10 Alice
20 Bob
30 Alice
40 Bob
50 Alice
60 Bob
70 Alice
80 Bob
90 Alice
100 Bob

Sample Output

Bob
Bob
tie
tie
Alice
tie
tie
tie
tie
Alice 找到n的所有素因子 依次说出一个素数乘以M
看谁轮到谁的时候M==N
如果M>N 则平局
找规律当 素因子种类大于3个的时候,
其实可以在两个回合内预判对方能不能赢和自己能不能赢
双方都能够判断所以最好的结果只能是tie 当素因子种类为2时,当素因子个数差大于1的时候 是没有解的 这个考自己找规律
就是一个对称博弈 ,这个就是先后手的问题了
当种类数为1的时候 这个就非常显然了
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <string>
#include <math.h>
#include <vector>
using namespace std; const int maxn = 1e5+; int vis[maxn], prime[maxn], k;
int sum[] ;
void init() {
memset(vis, , sizeof(vis));
k = ;
for (int i = ; i < maxn ; i++ ) {
if (vis[i]) continue;
for (int j = * i ; j < maxn ; j += i )
vis[j] = ;
vis[i] = ;
prime[k++] = i;
}
}
int main() {
int t;
init();
scanf("%d", &t);
while(t--) {
int n, tot = , m;
char name[];
memset(sum, , sizeof(sum));
scanf("%d%s", &n, name);
m = n;
for (int i = ; i < k && prime[i]*prime[i] <= m ; i++) {
if (m % prime[i] == ) {
while(m % prime[i] == ) {
sum[tot]++;
m = m / prime[i];
}
tot++;
}
}
if (m != ) {
sum[tot]++;
tot++;
}
if (tot >= ) printf("tie\n");
else if(tot == ) {
int temp = abs(sum[] - sum[]);
if (temp == ) printf("%s\n", (name[] == 'A') ? "Bob" : "Alice");
else if (temp == ) printf("%s\n", (name[] == 'B') ? "Bob" : "Alice");
else printf("tie\n");
} else if (tot == ) {
if (sum[] & ) printf("%s\n", (name[] == 'B') ? "Bob" : "Alice");
else printf("%s\n", (name[] == 'A') ? "Bob" : "Alice");
}
}
return ;
}

Multiplication Game(博弈论)的更多相关文章

  1. POJ2505 A multiplication game[博弈论]

    A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6028   Accepted:  ...

  2. 「POJ2505」A multiplication game [博弈论]

    题目链接:http://poj.org/problem?id=2505 题目大意: 两个人轮流玩游戏,Stan先手,数字 p从1开始,Stan乘以一个2-9的数,然后Ollie再乘以一个2-9的数,直 ...

  3. POJ2505 A multiplication game 博弈论 找规律

    http://poj.org/problem?id=2505 感觉博弈论只有找规律的印象已经在我心中埋下了种子... 题目大意:两个人轮流玩游戏,Stan先手,数字 p从1开始,Stan乘以一个2-9 ...

  4. hdu 1517 A Multiplication Game 博弈论

    思路:求必胜区间和必败区间! 1-9 先手胜 10-2*9后手胜 19-2*9*9先手胜 163-2*2*9*9后手胜 …… 易知右区间按9,2交替出现的,所以每次除以18,直到小于18时就可以直接判 ...

  5. [poj2505]A multiplication game_博弈论

    A mutiplication game poj-2505 题目大意:给定一个数n和p,两个选手每次可以将p乘上[2,9].最先使得p大于n的选手胜利. 注释:$1\le n\le 429496729 ...

  6. Multiplication Game

    Description Alice and Bob are in their class doing drills on multiplication and division. They quick ...

  7. IT人生知识分享:博弈论的理性思维

    背景: 昨天看了<最强大脑>,由于节目比较有争议性,不知为什么,作为一名感性的人,就想试一下如果自己理性分析会是怎样的呢? 过程是这样的: 中国队(3人)VS英国队(4人). 1:李建东( ...

  8. 【数学】Matrix Multiplication

                                 Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  9. hdu 4920 Matrix multiplication bitset优化常数

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

随机推荐

  1. 类的特殊方法"__call__"详解

    1. __call__ 当执行对象名+括号时, 会自动执行类中的"__call__"方法, 怎么用? class A: def __init__(self, name): self ...

  2. thinkphp centos7 报class POD not found

    没有安装PDO yum install php70w-pdo yum install php70w-mysqlnd 两条命令搞定

  3. R-描述性统计

    RT...老实说这一章我是抖的...但是,加油- # 从1:100中均匀抽取size个数据,replace=TRUE指有放回抽样,数据可以重复 x = sample(1:100, size = 100 ...

  4. GDOI--DAY2 游记

    今天,熬夜不够多,果然,不出所料,爆零了... 第一题,看到数据之大,懵逼了,于是,敲了个二分SPFA,但是!最大的点GG了,呜呜~~~~(>_<)~~~~ ,于是,就不继续做第一题了(虽 ...

  5. HyperLedger Fabric 1.4 区块链技术形成(1.2)

    在比特币诞生之时,没有区块链技术概念,当人们看到比特币在无中心干预的前提下,还能安全.可靠的运行,比特币网络打开了人们的想象空间:技术专家们开始研究比特币的底层技术,并抽象提取出来,形成区块链技术,或 ...

  6. [BZOJ3631][JLOI2014]松鼠的新家(树链剖分)

    [BZOJ3631] 树剖模板题了, Code #include <cstdio> #include <algorithm> #define MID int mid=(l+r) ...

  7. Leetcode 653. 两数之和 IV - 输入 BST

    题目链接 https://leetcode.com/problems/two-sum-iv-input-is-a-bst/description/ 题目描述 给定一个二叉搜索树和一个目标结果,如果 B ...

  8. 34-Cookie-based认证实现

    新建MVC项目,然后用VSCode打开 dotnet new mvc --name MvcCookieAuthSample 在Controllers文件夹下新建AdminController.cs u ...

  9. Microsxxxxxxx-面试总结

    策略题 There are four kinds of cards, respectively, 1,2, 3,4 numbers. There are seven cards for each ty ...

  10. Java进制间的转换

    最近学习了Java间的进制转换,记录下自己的学习心得,希望可以帮到前来查看的朋友们,如果有不懂的地方可以在下方评论留言,我们一起学习进步,只有自己足够强大才能弥补不足,多学习, 任意进制到十进制的转换 ...