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. C#基础-hashtable,泛型和字典集合

    hashtable 的存储方式 使用方法: 1.引入包含Hashtable的命名空间 using System.Collections; // 引入Hash所在的命名空间 2.往hash表里面添加数据 ...

  2. mongdb安装配置

    一.先登录Mongodb官网https://www.mongodb.com/download-center#community 下载   安装包.32.64位的都行. 或者查看我的百度云(使用win7 ...

  3. 【LeetCode #179】Largest Number 解题报告

    原题链接:Largest Number 题目描述: Given a list of non negative integers, arrange them such that they form th ...

  4. java实现 zip解压缩

    程序实现了ZIP压缩.共分为2部分 : 压缩(compression)与解压(decompression) 大致功能包括用了多态,递归等JAVA核心技术,可以对单个文件和任意级联文件夹进行压缩和解压. ...

  5. Linux基本的指令操作

    绝对路径: 路径的写法,由根目录/写起,例如:/usr/share/doc这个目录. 相对路径: 路径的写法,不由/写起,例如由/usr/share/doc要到/usr/share/man底下时,可以 ...

  6. python 函数复习

    # 函数 # 可读性强 复用性强 # def 函数名(): # 函数体 #return 返回值 # 所有的函数 只定义不调用就一定不执行 #先定义后调用 #函数名() #不接收返回值 #返回值 = 函 ...

  7. linux-shell——02

    Linux命令的通用命令格式 :命令字 [选项] [参数] 选项: 作用:用于调节命令的具体功能 "-"引导短格式选项(单个字符) EX:“-l” "--"引导 ...

  8. Color Length UVA - 1625 DP

    题目:题目链接 题意:输入两个长度分别为n和m的颜色序列,要求按顺序合并成同一个序列,即每次可以把一个序列开头的颜色放到新序列的尾部.对于每个颜色c来说,其跨度L(c)等于最大位置和最小位置之差,输出 ...

  9. 29-自己动手构建RequestDelegate管道

    1-使用vsCode新建个项目 2-新建RequestDelegate和Context public delegate Task RequestDelegate(Context context); p ...

  10. vue 组件间数据传递

    父组件向子组件传值 方法一: 子组件想要使用父组件的数据,需要通过子组件的 props 选项来获得父组件传过来的数据. 1.父组件parent.vue中代码: <template> < ...