Euclid's Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3174    Accepted Submission(s): 1474

Problem Description
Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser of the two numbers from the greater of the two numbers, provided that the resulting number must be nonnegative. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7):

25 7
11 7
4 7
4 3
1 3
1 0

an Stan wins.

 
Input
The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.
 
Output
For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly. The last line of input contains two zeroes and should not be processed.

 
Sample Input
34 12
15 24
0 0
 
Sample Output
Stan wins
Ollie wins
 
题意:给出了两个正数a.b,每次操作,大的数减掉小的数的整数倍。一个数变为0 的时候结束。

谁先先把其中一个数减为0的获胜。问谁可以赢。Stan是先手。

题解:没想太多打表过的。。

正确题解:

如果a==b.那么肯定是先手获胜。一步就可以减为0,b

如果a%b==0.就是a是b的倍数,那么也是先手获胜。

如果a>=2*b.  那么 那个人肯定知道a%b,b是必胜态还是必败态。如果是必败态,先手将a,b变成a%b,b,那么先手肯定赢。如果是必胜态,先手将a,b变成a%b+b,b.那么对手只有将这两个数变成a%b,b,先手获胜。

如果是b<a<2*b  那么只有一条路:变成a-b,b  (这个时候0<a-b<b).这样一直下去看谁先面对上面的必胜状态。

所以假如面对b < a <2*b的状态,就先一步一步走下去。直到面对一个a%b==0 || a >=2*b的状态。

#include<bits/stdc++.h>
#define N 35
#define mes(x) memset(x, 0, sizeof(x));
#define ll __int64
const long long mod = 1e9+;
const int MAX = 0x7ffffff;
using namespace std;
int dfs(int n, int m){
if(n > m) swap(n,m);
if(n >= *m) return ;
if(n == )
return ;
for(int i=m%n;i<m;i += n){
if(dfs(n, i) == )
return ;
}
return ;
}
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m)&&(n||m))
printf("%s\n", dfs(n,m)?"Stan wins":"Ollie wins");
}

HDU 1525 Euclid's Game 博弈的更多相关文章

  1. HDU 1525 Euclid's Game (博弈)

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. hdu 1525 Euclid's Game 博弈论

    思路:两个数a和b,总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况. 对于a/b==1这种局面, ...

  3. HDU 1525 Euclid's Game

    题目大意: 题目给出了两个正数a.b 每次操作,大的数减掉小的数的整数倍.一个数变为0 的时候结束. 谁先先把其中一个数减为0的获胜.问谁可以赢.Stan是先手. 题目思路: 无论a,b的值为多少,局 ...

  4. hdu 1525 Euclid's Game【 博弈论】

    Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtra ...

  5. HDU 1525 Euclid Game

    题目大意: 给定2个数a , b,假定b>=a总是从b中取走一个a的整数倍,也就是让 b-k*a(k*a<=b) 每人执行一步这个操作,最后得到0的人胜利结束游戏 (0,a)是一个终止态P ...

  6. HDU 1525 类Bash博弈

    给两数a,b,大的数b = b - a*k,a*k为不大于b的数,重复过程,直到一个数为0时,此时当前操作人胜. 可以发现如果每次b=b%a,那么GCD的步数决定了先手后手谁胜,而每次GCD的一步过程 ...

  7. A - 无聊的游戏 HDU - 1525(博弈)

    A - 无聊的游戏 HDU - 1525 疫情当下,有两个很无聊的人,小A和小B,准备玩一个游戏,玩法是这样的,从两个自然数开始比赛.第一个玩家小A从两个数字中的较大者减去两个数字中较小者的任何正倍数 ...

  8. hdu------(1525)Euclid's Game(博弈决策树)

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. HDU 1524 树上无环博弈 暴力SG

    一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...

随机推荐

  1. C语言如何开发简单的插件

    linux 通过dlopen来实现: #include "polygon.h" #include <stdlib.h> #include <dlfcn.h> ...

  2. C#读取Excel表格数据到DataGridView中和导出DataGridView中的数据到Excel

    其实想在datagridview中显示excel表格中的数据跟读取数据库中的数据没什么差别,只不过是创建数据库连接的时候连接字段稍有差别. private void btnShow_Click(obj ...

  3. xl2tp部署

    参考 http://blog.51yip.com/linux/1795.html 说到VPN,就会想到google,满心的疼.以前写过一篇关于vpn的文单,请参考:centos5.5 vpn 安装配置 ...

  4. 点餐系统3个sprint的团队贡献分

    第一次冲刺贡献分   团员名字 贡献分 麦锦俊 18分 冯婉莹 21分 李康梅 19分 张鑫相 20分 曹嘉琪 22分     第二次冲刺贡献分   团员名字 贡献分 麦锦俊 19分 冯婉莹 20分 ...

  5. Leetcode: Serialize and Deserialize BST

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  6. nginx----------------环境搭建遇到的一些问题汇总--(多域名配置,配置文件修改问题)

    nginx的启动命令是:(通用) /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 重启命令: /usr/local/ng ...

  7. Dll的生成,转化为OMF格式的DLL

    extern "C" { __declspec(dllexport) int psq_add(int a, int b); } C:\Users\pansq>mkexp my ...

  8. 计算ScrollView的当前页面

    //每页宽度 CGFloat pageWidth = sender.frame.size.width; //根据当前的坐标与页宽计算当前页码 int currentPage = floor((send ...

  9. Python字符串格式化

    一.使用格式化符来格式化字符串: Python支持的所有格式化符 格式化符 意义 'd' 返回要格式化对象的十进制表示,如果可以 'i' 返回要格式化对象的十进制表示,如果可以 'o' 返回要格式化对 ...

  10. 【原创】我所理解的自动更新-APP发布与后台发布

    发布后台 创建渠道:添加新的渠道,设置渠道名称,自动生成渠道id.    查看渠道:查看渠道基本信息,渠道app版本号,资源版本号,是否开启更新.    创建/更新APP:选择打包ios,androi ...