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 * @ ...
随机推荐
- [转]SIP穿越NAT&FireWall解决方案
原文链接(也是转载)http://blog.csdn.net/yetyongjin/article/details/6881491.我修改了部分错字. SIP从私网到公网会遇到什么样的问题呢? 1 ...
- django 简单的邮件系统
django邮件系统 Django发送邮件官方中文文档 总结如下: 1.首先这份文档看三两遍是不行的,很多东西再看一遍就通顺了. 2.send_mail().send_mass_mail()都是对Em ...
- [SAP ABAP开发技术总结]动态修改选择屏幕
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- kafka单节点部署无法访问问题解决
场景:在笔记本安装了一台虚拟机, 在本地的虚拟机上部署了一个kafka服务: 写了一个测试程序,在笔记本上运行测试程序,访问虚拟机上的kafka,报如下异常: 2015-01-15 09:33:26 ...
- 工具配置(eclipse/plsql)
PLSQL 附常用配置: PrefAutomaticStatistics=True SelectedStatNames= AutoSelectSQL=True ShowSQLWindowGutte ...
- 表单美化-原生javascript和jQuery单选按钮(兼容IE6)
最近很多人问怎么美化表单的元素,大家都知道表单元素在各个浏览器中的表现不一,反正也是特别的丑,那么问题就来了,我们能自己设计表单元素的外观么?答案是可以的,现在我们就来试试吧.我们用两种方式来实现这一 ...
- THE SENSE OF BEAUTY
#include<stdio.h> int main() { ][] = { " ,.:;j", " ,: i. .,:;ff", " : ...
- JavaScript基于对象(面向对象)<一>类和对象
javascript中一切皆对象,比如:Array,Date.....这些都是对象.javascript中没有class的定义,function既是定义函数,也可以是定义类.function Obj( ...
- odoo关联表查询方法
testinfo=self.env['product.attribute.value'].search([('product_ids.product_tmpl_id','=',2047)]) for ...
- Linux socket编程应用学习笔记
参考这个系列吧 http://www.cnblogs.com/wunaozai/tag/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/default.html?page=2 ...