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/ ... 
随机推荐
- struts2入门第一天----------配置环境
			放假之后有空就开始走上了三大框架的学习.第一个选择的框架是struts2.首先第一步当然是环境的配置.去apache官网把struts2下载下来.然后在自己的开发工具下创建一个web项目.在lib文件 ... 
- linux 安装 zookeeper
			第一步 下载 zookeeper: http://archive.apache.org/dist/zookeeper/ 第二步 解压: tar -xzvf zookeeper-3.4.5.tar.gz ... 
- tar工具(打包,压缩)
			tar工具(打包,压缩)========================= tar打包工具 -c:表示建立一个tar包或者压缩文件包-x:表示解包或者解压缩-v:表示可视化-f: 后面跟文件名(即-f ... 
- Linux下Mysql5.6 二进制安装
			1.1下载二进制安装包 wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.t ... 
- C# 禁止在textBox输入框输入非法字符
			首先添加下面代码 //禁止在textBox输入框输入非法字符 private void keypressed(Object o, KeyPressEventArgs e) { if (e.KeyCha ... 
- Git ---游离状态下的commit 分支切换与找回,commit之后无法找到历史记录
			commit之后无法找到历史记录 https://blog.csdn.net/zyb2017/article/details/78307688 
- 理解canvas路径
			canvas路径和ps里面的路径差不多,在进行图形绘制时,先绘制出来图形的路径,然后再描边或者填充. canvas路径还有子路径的概念,在某一时刻,canvas之中只能有一条路径存在,Canvas规范 ... 
- 动态调试smali代码
			Android Killer对应用进行反编译为smali代码,看看Manifest文件中application标签里面是否有android:debuggable="true",没有 ... 
- java实时监听日志写入kafka
			目的 实时监听某目录下的日志文件,如有新文件切换到新文件,并同步写入kafka,同时记录日志文件的行位置,以应对进程异常退出,能从上次的文件位置开始读取(考虑到效率,这里是每100条记一次,可调整) ... 
- PHP.14-图片处理类
			图片处理类 test.php <?php include "images.class.php"; $image=new Image("./images/" ... 
