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. 使用IDEA将本地项目上传到GitHub

    00.首先保证git和github能够使用ssh连接. 01.在GitHub上新建仓库 需要注意的是不要勾选Initialize this repository with a README. 02.在 ...

  2. nginx虚拟主机搭建

    nginx [engine x]是 Igor Sysoev 编写的一个 HTTP 和反向代理服务器,另外它也可以 作为邮件代理服务器. 它已经在众多流量很大的俄罗斯网站上使用了很长时间,这些网站包括 ...

  3. 2019-04-11 python入门学习——配置机器及搭建开发环境

    # 在windows操作系统中搭建python 3.x版本的开发环境,开发工具为 Anaconda 3. # 1.1 下载及安装Anaconda 3 Anaconda的特点:集成性高,包含很多常用的开 ...

  4. PPT入门学习笔记1:待修改

    一直被比人忽悠实在是累了,我可以接受自己的失误,但我接受不了别人一次又一次的坑我! 做PPT的原则是什么? 1.一个目标: "一个PPT只为一类人服务,针对不同的听众制作不同层次内容的PPT ...

  5. Linux设置下载站点

    https://blog.csdn.net/jfhkd2012/article/details/50912757

  6. Pandas 数据读取

    1.读取table # 读取普通分隔数据:read_table # 可以读取txt,csv import os os.chdir('F:/') #首先设置一下读取的路径 data1 = pd.read ...

  7. Postgres常用命令之增、删、改、查

    增.删.改.查: postgres=# \password postgres 为postgres进行密码设置: postgres=# CREATE USER test WITH PASSWORD '1 ...

  8. 可以字符串string转化成list,tuple,dict的eval()方法

    功能:将字符串str当成有效的表达式来求值并返回计算结果. 语法: eval(source[, globals[, locals]]) -> value 参数: source:一个Python表 ...

  9. 通过IIS共享文件夹来实现静态资源"本地分布式"部署

    以下以文件型数据库(如sqlite)为例 楼主话:以下内容,若有不专业处,大胆喷,虚心求教. 起因:要进行一个项目的分布式部署,而这个项目所涉及的其中一个数据库为sqlite(经测试,同为文件型数据库 ...

  10. Android Config通用类来记录信息

    1.整体分析 1.1.源代码,可以直接Copy. public class Config { private static int M = 1024 * 1024; private volatile ...