HDU1525 Euclid's Game
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.
InputThe input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.OutputFor 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的为胜者。
错误思路:
最开始我是这样想的:(a,b)->(b,a%b),算一个转移,中间可以减a/b次;(b,a%b)->(a%b,b%(a%b))需要..次。把每一个转移看成一个堆,那么每堆可以任选,就成了Nim博弈了。代码如下:
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int Xor,a,b;
while(~scanf("%d%d",&a,&b)){
if(a==&&b==) return ;
Xor=;
while(true){
if(a==||b==) break;
if(a<b) swap(a,b);
Xor=Xor^(a/b);
a=a%b;
}
if(Xor) printf("Stan wins\n");
else printf("Ollie wins\n");
} return ;
}
但是这样做是有问题的,因为Nim博弈是任选一堆的任意个,而这样转化的从前往后的堆里选任意个。所以不一样。
正确打开方式: 假设a大于b a == b. N态 a%b == 0. N态
a >= 2*b,先手能决定谁取(b,a%b),并且知道(b,a%b)是P态还是N态. N态
b<a<2*b, 只能 -->(b,a-b) , 然后再进行前面的判断.
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int num,a,b;
while(~scanf("%d%d",&a,&b)){
if(a==&&b==) return ;
num=;
while(true){
if(a<b) swap(a,b);
if(a%b==||b==) break;
if(a>=*b) break;
a=a%b;
num++;
}
if(num&) printf("Stan wins\n");
else printf("Ollie wins\n");
} return ;
}
HDU1525 Euclid's Game的更多相关文章
- hdu------(1525)Euclid's Game(博弈决策树)
Euclid's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu1525 Euclid's Game , 基础博弈
http://acm.hdu.edu.cn/showproblem.php?pid=1525 题意: 两人博弈,给出两个数a和b, 较大数减去较小数的随意倍数.结果不能小于0,将两个数随意一个数减到0 ...
- DU1525 Euclid's Game 博弈
HDU1525 Euclid's Game 博弈 题意 给定两个数字 a, b. 每次只能用 较大的值 减去 较小的值的倍数, 两个人轮流进行操作, 第一个得到 0 的胜利. 分析 对于 a == b ...
- 基础博弈论之——简单的博弈问题【hdu1525】【Euclid‘s Game】
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=60481118 由于今天考了一道博弈的问题,我竟什 ...
- ZOJ1913 Euclid's Game (第一道简单的博弈题)
题目描述: Euclid's Game Time Limit: 2 Seconds Memory Limit: 65536 KB Two players, Stan and Ollie, p ...
- Euclid求最大公约数
Euclid求最大公约数算法 #include <stdio.h> int gcd(int x,int y){ while(x!=y){ if(x>y) x=x-y; else y= ...
- HDU 1525 Euclid's Game 博弈
Euclid's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- [poj2348]Euclid's Game(博弈论+gcd)
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9033 Accepted: 3695 Des ...
- HDU 1525 Euclid's Game (博弈)
Euclid's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- C# 通过WebService方式 IIS发布网站 上传文件到服务器[转]
http://blog.sina.com.cn/s/blog_517cae3c0102v0y7.html 应用场景:要将本地的文件 上传到服务器的虚拟机上 网络环境:公司局域网(如下图中第二种) 开发 ...
- qt实现又一次登录
1.需求 须要实现程序操作过程中的又一次启动,即常常说的又一次登录功能 2.解决 在main函数中检測exec的返回值决定是关闭还是重新启动.使用注冊函数atexit(relogin)来实现这个功能 ...
- AngularJS的表单验证提交示例
代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsFormSubmit.rar 前台代码: <%@ page content ...
- class文件结构浅析(2)
欢迎转载,转载需声明出处 ------------------ 请先看上一篇:Class类文件结构浅析 上一篇讲的都是理论.以下我们亲自实践一下. 首先编写一个简单的java类: public cla ...
- 有关C/C++指针的经典面试题(转)
参考一: 有关C/C++指针的经典面试题 0.预备知识,最基础的指针 其实最基础的指针也就应该如下面代码: int a; int* p=&a; 也就是说,声明了一个int变量a,然后声明一个i ...
- Sql语言复习
一.创建数据库 创建和打开数据库 注意一点:在新建数据库的时候,一般放置数据文件与日志文件的位置,需要提前建立文件夹,不然会报错. 一般主数据文件,我们以.mdf结尾,次数据文件用.ndf结尾.对于日 ...
- ES7前端异步玩法:async/await理解 js原生API妙用(一)
ES7前端异步玩法:async/await理解 在最新的ES7(ES2017)中提出的前端异步特性:async.await. 什么是async.await? async顾名思义是“异步”的意思,a ...
- 认识Gulp
gulp详细入门教程:http://www.ydcss.com/archives/18 安装gulp 前提:已经安装node.js.npm $ npm install gulp --save-dev ...
- 手机pc显示不同的内容
<script type="text/javascript"> // var txt = $('#sjyincang').html(); // alert(txt); ...
- JMeter中使用Put请求方式请求接口
前言 现在有如下接口,是以PUT的方式请求的: 请求URL:IP+Port+/api/v1/apps/{appId} 请求参数: 参数名 必选 类型 nameCn 是 string nameEn 是 ...