hdu------(1525)Euclid's Game(博弈决策树)
Euclid's Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2074 Accepted Submission(s): 924
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 consists of a number of lines. Each line contains two positive
integers giving the starting two numbers of the game. Stan always
starts.
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.
15 24
0 0
Ollie wins
#include<cstring>
#include<cstdio>
bool flag=false;
int cont=;
void botree(int n,int m){
if(n<m)n^=m^=n^=m;
if(n%m)
for(int i=;i*m<n;i++){
cont++;
botree(n-i*m,m);
}
else {
if(cont&) flag=true;
cont=;
}
}
int main(){
int n,m;
//freopen("test.in","r",stdin);
while(scanf("%d%d",&n,&m),n+m){
flag=false;
botree(n,m);
if(flag) printf("Stan wins\n");
else printf("Ollie wins\n");
}
return ;
}
然后进行了优化之后.....得到这样的代码:
/*Problem : 1525 ( Euclid's Game ) Judge Status : Accepted
RunId : 11528629 Language : C++ Author : huifeidmeng
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta*/ #include<cstring>
#include<cstdio>
bool flag=false;
int cont=,cc=;
void botree(int n,int m){
if(n<m) n^=m^=n^=m;
if(m>&&((n%m)&&n/m==)){
cont++;
botree(n%m,m);
}
else if(cont&) flag=true;
}
int main(){
int n,m;
//freopen("test.in","r",stdin);
while(scanf("%d%d",&n,&m),n+m){
flag=false;
cont=;
botree(n,m);
if(flag) printf("Stan wins\n");
else printf("Ollie wins\n");
}
return ;
}
hdu------(1525)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 ...
- HDU 1525 Euclid's Game (博弈)
Euclid's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1525 Euclid's Game 博弈论
思路:两个数a和b,总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况. 对于a/b==1这种局面, ...
- HDU 1525 Euclid's Game
题目大意: 题目给出了两个正数a.b 每次操作,大的数减掉小的数的整数倍.一个数变为0 的时候结束. 谁先先把其中一个数减为0的获胜.问谁可以赢.Stan是先手. 题目思路: 无论a,b的值为多少,局 ...
- hdu 1525 Euclid's Game【 博弈论】
Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtra ...
- HDU 1525 Euclid Game
题目大意: 给定2个数a , b,假定b>=a总是从b中取走一个a的整数倍,也就是让 b-k*a(k*a<=b) 每人执行一步这个操作,最后得到0的人胜利结束游戏 (0,a)是一个终止态P ...
- HDU 1525 类Bash博弈
给两数a,b,大的数b = b - a*k,a*k为不大于b的数,重复过程,直到一个数为0时,此时当前操作人胜. 可以发现如果每次b=b%a,那么GCD的步数决定了先手后手谁胜,而每次GCD的一步过程 ...
- A - 无聊的游戏 HDU - 1525(博弈)
A - 无聊的游戏 HDU - 1525 疫情当下,有两个很无聊的人,小A和小B,准备玩一个游戏,玩法是这样的,从两个自然数开始比赛.第一个玩家小A从两个数字中的较大者减去两个数字中较小者的任何正倍数 ...
- HDU 1524 树上无环博弈 暴力SG
一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...
随机推荐
- [转]C# List<T>的详细用法
所属命名空间:System.Collections.Generic publicclassList<T> : IList<T>,ICollection<T>, IE ...
- debian hosts文件中的 127.0.1.1 主机地址
有时候/etc/hosts文件会看到127.0.1.1这个地址,这是什么呢? 127.0.0.1这个loopback地址很常见,就是本地接口的回路/回环地址.但有时候/etc/hosts文件中还会出现 ...
- struts2--表单标签
struts2的表单标签可分为两类:form标签本身和包装HTML表单元素的其他标签.form标签本身的行为不同于它内部的元素. struts2表单标签包括: form.textfield.passw ...
- 测试框架Mockito使用笔记
Mockito,测试框架,语法简单,功能强大! 静态.私有.构造等方法测试需要配合PowerMock,PowerMock有Mockito和EasyMock两个版本,语法相同,本文只介绍Mockito. ...
- Python基础学习笔记(九)常用数据类型转换函数
参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-variable-types.html 3. http://www ...
- git学习笔记08-分支管理策略-实际上我们应该怎么应用分支
Git用Fast forward模式(快进模式),但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的commit,这样,从分支 ...
- shift移动变量
1.移动变量 脚本 sh05.sh #!/bin/bash # Program # Program shows the effect of shift function # History: # // ...
- 使用ultramon调整任务栏高度
取消锁定,调整任务栏的高度为一行图标的高度,然后再锁定即可.为啥程序没有默认设置?
- sqlcmd 登录和执行语句。
sqlcmd -U sa -P atc@2014 -S HK-DB01 -d msdb -Q "exec sp_start_job @job_name='3PL_OUT_TEST'" ...
- java或者jsp中修复会话标识未更新漏洞
AppScan会扫描“登录行为”前后的Cookie,其中会对其中的JSESSIONOID(或者别的cookie id依应用而定)进行记录.在登录行为发生后,如果cookie中这个值没有发生变化,则判定 ...