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
Hint
博弈论;质因数分为 一种,两种,和多种,多种必平局,一种时,该质因数数量为奇数时,第一个人胜,偶数则第二个人胜;
两种时,若两种数量相同,则第二个人胜,若相差一个,则第一个胜,否则平局。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;
const int maxn = 1e5+100;
int prime[maxn+10];
bool vis[maxn];
ll cnt;
void judge(int n)
{
cnt=0;
vis[1]=true;
ll i,j;
for(i=2; i<=n; i++)
{
if(!vis[i])
{
prime[cnt++]=i;
}
for(j=0; j<cnt && i*prime[j] <= n; j++)
{
vis[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
}
int main()
{
judge(maxn);
int T;
cin>>T;
while(T--)
{
ll n;
string ss;
cin>>n>>ss;
int ret = 0;
vector<int> v;
for(int i=0; i<cnt; i++)
{
if(n%prime[i]==0)
{
ret++;
int tmp=0;
while(n%prime[i]==0)
{
n/=prime[i];
tmp++;
}
v.push_back(tmp);
}
if(ret>=3) break;
}
if(n>1)
{
ret++;
v.push_back(1);
}
if(ret>=3) cout<<"tie"<<endl;
else if(ret==1)
{
if(v[0]%2==0)
{
if(ss=="Alice") cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
else
{
if(ss!="Alice") cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
}
else if(ret==2)
{
if(v[1]==v[0])
{
if(ss=="Alice") cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
else
{
if(abs(v[0]-v[1])==1)
{
if(ss!="Alice") cout<<"Bob"<<endl;
else cout<<"Alice"<<endl;
}
else cout<<"tie"<<endl;
}
}
else cout<<ss<<endl;
}
return 0;
}
/**********************************************************************
Problem: 2115
User: song_hai_lei
Language: C++
Result: AC
Time:1456 ms
Memory:2512 kb
**********************************************************************/
Multiplication Game的更多相关文章
- POJ2505 A multiplication game[博弈论]
A multiplication game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6028 Accepted: ...
- 【数学】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/ ...
- 矩阵乘法 --- hdu 4920 : Matrix multiplication
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- Booth Multiplication Algorithm [ASM-MIPS]
A typical implementation Booth's algorithm can be implemented by repeatedly adding (with ordinary un ...
- hdu4951 Multiplication table (乘法表的奥秘)
http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...
- hdu4920 Matrix multiplication 模3矩阵乘法
hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...
- 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence
题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...
- Matrix Chain Multiplication[HDU1082]
Matrix Chain Multiplication Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
随机推荐
- ARP通信
ARP:地址解析协议,是根据IP地址获取物理地址的一个TCP/IP协议 简单介绍ARP通信过程: 1.发送端在与接收端进行数据通信转发时的过程: 发送端与接收端进行数据通信之前,需要先知道对端的MAC ...
- 手把手教你用netty撸一个ZkClient
原文地址: https://juejin.im/post/5dd296c0e51d4508182449a6 前言 有这个想法的缘由是前一阵子突发奇想, 想尝试能不能直接利用js连接到zookeeper ...
- ACE框架 基于共享内存的进程间通讯
ACE框架将基于共享内存的进程间通讯功能,如其它IO组件或IPC组件一样,设计成三个组件.流操作组件ACE_MEM_Stream,连接器组件ACE_MEM_Connector,以及接收连接组件ACE_ ...
- pod删除主要流程源码解析
本文以v1.12版本进行分析 当一个pod删除时,client端向apiserver发送请求,apiserver将pod的deletionTimestamp打上时间.kubelet watch到该事件 ...
- 万恶之源-python基本数据类型
万恶之源-基本数据类型(dict) 本节主要内容: 字典的简单介绍 字典增删改查和其他操作 3. 字典的嵌套 ⼀一. 字典的简单介绍 字典(dict)是python中唯⼀一的⼀一个映射类型.他是以{ ...
- windows下搭建dubbo 环境(dubbo-admin和服务提供者消费者)
---恢复内容开始--- 一. dubbo-admin管理控制台 从 https://github.com/apache/dubbo-admin clone项目到本地. 修改dubbo-admin- ...
- HTTP基础及telnet简单命令
一.HTTP概况 20世纪90年代初期,一个主要的新兴应用即万维网(World Wide Web)登上了舞台.Web是一个引起公众注意的因特网应用.Web的应用层协议是超文本传输协议(HTTP),它是 ...
- WPF 修改屏幕DPI,会触发控件重新加载Unload/Load
修改屏幕DPI,会触发控件的Unloaded/Loaded 现象/重现案例 对Unloaded/Loaded的印象: FrameworkElement, 第一次加载显示时,会触发Loaded.元素被释 ...
- python3 之 变量作用域详解
作用域: 指命名空间可直接访问的python程序的文本区域,这里的 ‘可直接访问’ 意味着:对名称的引用(非限定),会尝试在命名空间中查找名称: L:local,局部作用域,即函数中定义的变量: E: ...
- python3 之 趣味数学题(爱因斯坦)
爱因斯坦曾出过这样一道有趣的数学题: 有一个长阶梯,若每步上 2 阶,最 后剩 1 阶; 若每步上 3 阶,最后剩 2 阶; 若每步上 5 阶,最后剩 4 阶; 若每步上 6 阶,最后剩 5 阶; 只 ...