Multiplication Game(博弈论)
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(博弈论)的更多相关文章
- POJ2505 A multiplication game[博弈论]
A multiplication game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6028 Accepted: ...
- 「POJ2505」A multiplication game [博弈论]
题目链接:http://poj.org/problem?id=2505 题目大意: 两个人轮流玩游戏,Stan先手,数字 p从1开始,Stan乘以一个2-9的数,然后Ollie再乘以一个2-9的数,直 ...
- POJ2505 A multiplication game 博弈论 找规律
http://poj.org/problem?id=2505 感觉博弈论只有找规律的印象已经在我心中埋下了种子... 题目大意:两个人轮流玩游戏,Stan先手,数字 p从1开始,Stan乘以一个2-9 ...
- hdu 1517 A Multiplication Game 博弈论
思路:求必胜区间和必败区间! 1-9 先手胜 10-2*9后手胜 19-2*9*9先手胜 163-2*2*9*9后手胜 …… 易知右区间按9,2交替出现的,所以每次除以18,直到小于18时就可以直接判 ...
- [poj2505]A multiplication game_博弈论
A mutiplication game poj-2505 题目大意:给定一个数n和p,两个选手每次可以将p乘上[2,9].最先使得p大于n的选手胜利. 注释:$1\le n\le 429496729 ...
- Multiplication Game
Description Alice and Bob are in their class doing drills on multiplication and division. They quick ...
- IT人生知识分享:博弈论的理性思维
背景: 昨天看了<最强大脑>,由于节目比较有争议性,不知为什么,作为一名感性的人,就想试一下如果自己理性分析会是怎样的呢? 过程是这样的: 中国队(3人)VS英国队(4人). 1:李建东( ...
- 【数学】Matrix Multiplication
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total S ...
- hdu 4920 Matrix multiplication bitset优化常数
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
随机推荐
- SEOer必读:50个网站推广方法
1.论坛推广 这里所说的论坛推广绝对不是在论坛里一个一个版贴广告,也不是将网站地址加在签名里然后疯狂刷屏,那样既耗费精力而且效果也不见得好,论坛管理员只要点几下鼠标就能将你的帖子全部删除,顺便封掉你的 ...
- linux特殊权限位suid
特殊权限位基本说明(了解): linux系统基本权限位为9位权限,但还有额外3位权限位,共12位权限: suid s(x) S 4 用户对应的权限位(用户对应的3位 ...
- source tree 使用心得
SourceTree 是 Windows 和Mac OS X 下免费的 Git 和 Hg 客户端管理工具,同时也是Mercurial和Subversion版本控制系统工具.支持创建.克隆.提交.pus ...
- [回文树][BZOJ2160][国家集训队]拉拉队排练
题面 Description 艾利斯顿商学院篮球队要参加一年一度的市篮球比赛了.拉拉队是篮球比赛的一个看点,好的拉拉队往往能帮助球队增加士气,赢得最终的比赛.所以作为拉拉队队长的楚雨荨同学知道,帮助篮 ...
- python基础之入门基础
编程语言分类 机器语言 使用二进制代码直接编程,直接与硬件交互,执行速度非常快,灵活,但是开发难度高,开发效率低下,缺乏移植性. 汇编语言 对机器语言指令进行了英文封装,较机器语言容易记忆,直接与硬件 ...
- 20145202马超GDB调试汇编堆栈过程分析
20145202马超GDB调试汇编堆栈过程分析 esc :w保存,:wq保存并退出 x:删除错误的单个字母 dw:删除整个单词 gcc hello.c -o hello:运行hello.c gcc - ...
- PHP.16-PDO
PHP 数据对象 (PDO) 扩展为PHP访问数据库定义了一个轻量级的一致接口.实现 PDO 接口的每个数据库驱动可以公开具体数据库的特性作为标准扩展功能. 注意利用 PDO 扩展自身并不能实现任何数 ...
- ThinkPad 触控板双指不可以滑动
我一直在想为什么,今天我想禁用触摸板的时候,我找到原因了. 是因为没有装驱动. http://think.lenovo.com.cn/support/driver/newdriversdownlist ...
- CentOS 6.0 VNC远程桌面配置[转]
原文出处: http://blog.haohtml.com/archives/12281 谢谢作者. 引言:必须明白:vncserver在调用的时候,会根据你的配置来启用server端的监听端口,端口 ...
- “管中窥豹”,MyCAT的基因缺陷
提起MyCAT,我的脑海里,总是浮现出这样一首偈.弘忍觉得自己老了,需要找一个接班人,于是,弘忍要求弟子们每人写一个偈子,根据偈子观察各位弟子的开悟程度,从而传授正宗禅宗的衣钵.弟子们心里其实都很明白 ...