HDU 3595 GG and MM(Every-SG)
Problem Description
GG and MM like playing a game since they are children. At the beginning of game, there are two piles of stones. MM chooses a pile of stones first, which has x stones, and then she can choose a positive number k and remove k*x stones out from the other pile of stones, which has y stones (I think all of you know that y>=k*x - -!). Then it comes the turn of GG, followed the rules above-mentioned as well. When someone can't remove any stone, then he/she loses the game, and this game is finished. Many years later, GG and MM find this game is too simple, so they decided to play N games at one time for fun. MM plays first, as the same, and the one on his/her turn must play every unfinished game. Rules to remove are as same as above, and if someone cannot remove any stone (i.e., loses the last ending game), then he/she loses. Of course we can assume GG and MM are clever enough, and GG will not lose intentionally, O(∩_∩)O~
Input
The input file contains multiply test cases (no more than 100). The first line of each test case is an integer N, N<=1000, which represents there are N games, then N lines following, each line has two numbers: p and q, standing for the number of the two piles of stones of each game, p, q<=1000(it seems that they are so leisure = =!), which represent the numbers of two piles of stones of every game. The input will end with EOF.
Output
For each test case, output the name of the winner.
Sample Input
3 1 1 1 1 1 1 1 3 2
Sample Output
MM GG
Author
alpc95
Source
2010 ACM-ICPC Multi-University Training Contest(16)——Host by NUDT
Recommend
zhengfeng | We have carefully selected several similar problems for you: 3600 3593 3599 3598 3594
题意:一共有n个游戏,每一个游戏有两堆石子,一次移动可以从大的那堆石子里拿小的那堆石子的整数倍的石子。
只要是可以操作的游戏都要进行操作,不能进行操作的人负。
比较神的博弈
模型是Every-SG肯定是没问题,框架按套路写就可以
有一个比较显然的结论
设两个数为(x,y),那么当frac{y}{x}>1,此时先手必胜,因为先手可能通过控制倍数来控制接下来步数的奇偶性
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
const int MAXN=1001;
inline int read()
{
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int a[MAXN],b[MAXN],SG[MAXN][MAXN],step[MAXN][MAXN];
int GetSG(int x,int y)
{
if(x>y) std::swap(x,y);
if(SG[x][y]!=-1) return SG[x][y];
if(!x||!y) return SG[x][y]=step[x][y]=0;
int willx=y%x,willy=x;
int k=y/x;
if(k==1)
{
SG[x][y]=GetSG(willx,willy)^1;
step[x][y]=step[willx][willy]+1;
return SG[x][y];
}
else
{
step[x][y]=GetSG(willx,willy)+step[willx][willy]+1;
return SG[x][y]=1;//此时先手必胜
}
}
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
memset(SG,-1,sizeof(SG));
int N;
while(scanf("%d",&N)!=EOF)
{
int ans=0;
for(int i=1;i<=N;i++)
{
int x=read(),y=read();
if(x>y) std::swap(x,y);
GetSG(x,y);
ans=std::max(ans,step[x][y]);
}
puts(ans%2?"MM":"GG");
}
return 0;
}
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- HTML转PDF工具Wkhtmltopdf安装使用
- 【Vue.js】Vue.js组件库Element中的时间选择器、日期选择器、日期时间选择器和颜色选择器
- 【Vue.js】Vue.js的Chrome浏览器开发插件DevTools的安装步骤
- 训练提速60%!只需5行代码,PyTorch 1.6即将原生支持自动混合精度训练。
- TensorFlow 模型剪枝
- 机器人如何使用 RRT 进行路径规划?
- 高效 PyTorch:6个训练Tips
- 机器学习与情绪交易(附代码)
- 社区前端游戏框架LollipopCreator v1.0.X正式开源
- 社区开源框架音效管理模块:AudioManager详解
- 社区开源框架音效管理模块:AvatarManager详解
- vue-element-admin实现一个可编辑的table
- vue+element实现一个excel表格下载的功能
- vue的select下拉框多选项-multiple属性
- HBase基准测试