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 ...
随机推荐
- [git]关于github的一些用法笔记(入门)
本视频来自于观看尚硅谷B站教学:https://www.bilibili.com/video/av10475153?from=search&seid=9735863941344749813 而 ...
- java编程思想第四版第十四章 类型信息总结
1. Class 对象: 所有的类都是在对其第一次使用的时候,动态加载到JVM中的.当程序创建第一个对类的静态成员的引用时,就会加载这个类.这说明构造器也是类的静态方法.即使在构造器之前并没有stat ...
- 如何在当前文件夹打开cmd(基于win10)
如何在当前文件夹打开cmd(基于win10) 方法一: 1.先打开你要进入的文件夹 2.在标记的位置输入cmd,就可以进入当前文件的cmd 方法二: 1.打开你要进入的文件夹 2.通过shift + ...
- ArcGIS API For Javascript :如何制作地图切换器
大部分情况下我们开发会使用原生的地图切换器,由于每个项目的页面风格不同,业务场景不同,因此需要做一些样式不同的地图切换器. 首先可以照猫画虎,自己照着地图切换器的样式抄一个,或者看看主流的地图切换器都 ...
- 使用zuul实现验证自定义请求头中的token
路由:她会把外部所有对请求转发到具体的微服务实例上,是实现外部访问同一接口的基础 过滤: 就是权限的检查, 判断当前的请求是否有权限区访问那些服务集群 搭建后台网关: 导入eureka - clien ...
- 【Luogu P1878】舞蹈课
Luogu P1878 事实上这道题并不难,但我真没弄懂我手写堆为什么过不了.所以 STL大法好!!! 基本思路 对于每一对相邻异性,将他们的舞蹈技术的差插入一个堆 通过维护这个小根堆,每次就可以取得 ...
- 【计算机网络】你真的了解HTTP(HTTPS)协议的这12个知识点吗
HTTP协议 1. 介绍一下OSI七层参考模型和TCP/IP五层模型 1.1 OSI七层模型 1.2 TCP/IP五层模型 1.3 各层的设备 [各层设备] 1.4 各层对应协议 2. HTTP协议和 ...
- 前端vue实现pdf文件的在线预览
3.前端vue实现pdf文件的在线预览 我是通过 <iframe> 标签就可以满足我工作的 pdf预览需求 如果<iframe> 无法满足需求 , 可以使用pdf.js这个插件 ...
- Sting类字符串
一.声明字符串 在java语言中字符串必须包含在一对双引号(" ")之内,但不能作为其他数据类型来使用,如"1+2"的输出结果不可能是3: 可以通过以下语法格式 ...
- centos 7 MysSQL 5.6.39 源码安装
MySQL 5.6.39 二进制安装 CentOS 7 将默认数据库MySQL替换成了Mariadb. 这里会从系统的环境准备开始一步一步安装. 环境准备 系统版本 内核版本 IP地址 Centos ...