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 * @ ...
随机推荐
- [转]GameObject的Active与InActive
GameObject的Active与InActive 1.Script可以控制InActive的GameObject,但前提是Script所依附的GameObject不能是InActive,一旦为In ...
- 关于stl string find 容易犯的一个错误
有时候经常会判断一个字符串a中是否有子字符串b,那么有人会调用 string::find这个函数 这个函数返回子字符串首次出现的位置,那么有人会这样写 string str1 = "&qu ...
- [HDOJ3308]LCIS(线段树,区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题意:给定n个数,两个操作: U A B:将位置A的数值改成B Q A B:查询[A,B]内最长 ...
- 2dx中文乱码问题
我们的代码里面有一个bug 为了跟之前兼容的策划导表工具兼容 导表工具导出的excel全部都是ansi的 为了兼容就只能手动改成utf 8 无bom格式 后来策划嫌烦了 就让在程序段处理这个 研究了好 ...
- [转]ubuntu环境变量配置文件
参考网址:http://www.bkjia.com/Linuxjc/1008127.html Ubuntu通常使用的几个配置文件主要有下面这几个: /etc/environment./etc/prof ...
- 07 SQL优化技术
本章提要------------------------------------------------------调优技术及什么时候使用------------------------------- ...
- sqlserver 批量删除存储过程(转)
sqlserver一次只能删除一个存储过程,如果多了,需要很长时间才能删完,所以写了一段语句,直接就把当然数据库下所有用户自定义的存储过程给drop了.不过使用都请留心,当前打开的数据库哦.下面贴代码 ...
- Oracle的热备份
一. 什么是热备份 热备份也叫联机备份,它是指数据库处于open状态下,对数据库的数据文件.控制文件.参数文件.密码文件等进行一系列备份操作(其中数据文件是必须备份的). 它要求数据库处在归档模式下. ...
- (三)VLAN基本概念
- Linux用户查询
用户列表文件:/etc/passwd 用户组列表文件:/etc/group 查看系统中有哪些用户:cut -d : -f 1 /etc/passwd 查看可以登录系统的用户:cat /etc/pass ...