$ \color{#0066ff}{ 题目描述 }$

两堆石子,GG和MM轮流取,每次在一堆石子中取另一堆石子的k\((k\ge1)\)倍,不能操作的输

现在二人要玩n个这样的游戏,每回合每个人对每个未完成的游戏进行操作,胜负取决于最后一个游戏的结果

问能否先手必胜

\(\color{#0066ff}{输入格式}\)

多组数据

第一行一个n

接下来n行为每个游戏的两堆石子

\(\color{#0066ff}{输出格式}\)

每组数据输出谁能赢(MM先手)

\(\color{#0066ff}{输入样例}\)

3
1 1
1 1
1 1
1
3 2

\(\color{#0066ff}{输出样例}\)

MM
GG

\(\color{#0066ff}{数据范围与提示}\)

数据组数\(\le 100\)

n和每堆石子数都\(\le 1000\)

\(\color{#0066ff}{题解}\)

看到对已存在的游戏都要操作,那就是EverySG了

与普通SG不同的是,多了时间这一维

记录一个step,与sg同维

最后step大的必胜

step的转移

如果当前是必胜态,那么从所有必败态的step取max+1转移过来

如果当前是必败态,那么从所有必胜态的step取min+1转移过来

#include <cctype>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
const int inf = 0x7fffffff;
const int maxn = 1050;
int sg[maxn][maxn];
int step[maxn][maxn];
bool vis[maxn * maxn];
int work(int x, int y) {
if(x > y) std::swap(x, y);
if(!x || !y) return sg[x][y] = step[x][y] = 0;
if(~sg[x][y]) return sg[x][y];
int max = 0, min = inf;
for(int k = 1; k * x <= y; k++) work(x, y - x * k);
for(int k = 1; k * x <= y; k++) {
int xx = x, yy = y - x * k;
if(xx > yy) std::swap(xx, yy);
vis[sg[xx][yy]] = true;
if(sg[xx][yy]) min = std::min(min, step[xx][yy]);
if(!sg[xx][yy]) max = std::max(max, step[xx][yy]);
}
for(sg[x][y] = 0; vis[sg[x][y]]; sg[x][y]++);
if(sg[x][y]) step[x][y] = max + 1;
else step[x][y] = min + 1;
for(int k = 1; k * x <= y; k++) {
int xx = x, yy = y - x * k;
if(xx > yy) std::swap(xx, yy);
vis[sg[xx][yy]] = false;
}
return sg[x][y];
}
int main() {
int n;
memset(sg, -1, sizeof sg);
while(~scanf("%d", &n)) {
int x, y, GG = 0, MM = 0;
for(int i = 1; i <= n; i++) {
x = in(), y = in();
if(x > y) std::swap(x, y);
work(x, y);
if(sg[x][y]) MM = std::max(MM, step[x][y]);
else GG = std::max(GG, step[x][y]);
}
puts(MM < GG? "GG" : "MM");
}
return 0;
}

最新文章

  1. 12小时包你学会基于ReactMix框架的ReactNativeApp开发(一)Hello World!
  2. 自定义底部tab
  3. IBM的IT战略规划方法论
  4. 第一个Sprint冲刺第四天
  5. 工作中遇到的问题--BindException
  6. kuangbin_ShortPath M (POJ 1062)
  7. AS3 - 数组Array的几个常用方法(附样例)
  8. VS2005配置CPPUnit进行单元測试
  9. 在 APK 中找不到对应的 securityguard***.so 文件或者 so 文件载入出错
  10. Oracle和MSSQL查询有多少张表
  11. js共享onload事件
  12. (转)JSON 之FastJson解析
  13. STL中map用法
  14. Linux 零拷贝技术
  15. android四大组件学习总结以及各个组件示例(1)
  16. Loadrunner 网页诊断图
  17. vue.js小总结
  18. 20172328《程序设计与数据结构》实验三 敏捷开发与XP实践报告
  19. 多路径multipath配置,udev绑定
  20. IDA远程调试 在内存中dump Dex文件

热门文章

  1. OpenGL ES &amp; SDL(转载)
  2. 对象序列化中transient关键字的用途
  3. 为什么学习python?(知乎大神的回答)
  4. spring 项目返回406
  5. AC自动机详解
  6. PrimeNG01 angular集成PrimeNG
  7. the install of mysql in Linux System
  8. SQL 数据排重,去掉重复数据 有用
  9. linux的deamon后台运行
  10. Apache ab命令