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 * @ ...
随机推荐
- js对cookie的操作,包括增,取,删
在其他人都开会到时间里,我偷偷摸哦的试了一下cookie,唉,从来没有用过cookie,慢慢的知识忘光了,还好这次偷偷摸摸的做出来了,虚,大家都别出声啊 <!DOCTYPE html> & ...
- 第一次写python爬虫
花了4天终于把写完了把国内的几个漏洞平台爬完了,第一次写py,之前一直都在说学习,然后这周任务是把国内的漏洞信息爬取一下.花了1天学PY,剩下的1天一个.期间学习到了很多.总结如下: ======== ...
- git 简单用
之前一直用svn,用git也只是从github上clone代码.现在自己试试用git做版本控制.等用熟悉了,再看看怎么搞分支,合并,多人开发之类的. 1下载个git客户端,如Git for Windo ...
- 一个ListBox的例子
1.向ListBox中放入其他控件 XAML: <Window x:Class="ItemsControls.MainWindow" xmlns="http://s ...
- Python基础学习笔记(七)常用元组内置函数
参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-tuples.html 3. http://www.liaoxue ...
- 个人博客作业WEEK 1
一.项目时间规划与实际用时 PSP2.1 Personal Software Process Stages 预计时间/h 实际时间/h Planning 计划 · Estimate · 估计这个任 ...
- 2013 Multi-University Training Contest 8
HDU-4676 Sum Of Gcd 题意:给定一个1-N的全排列序列,N<=20000,有Q组询问,Q<=20000,每组询问给出左右区间[l, r],问区间内的任意两个数的gcd之和 ...
- Spring security3入门(转)
http://kingxss.iteye.com/blog/1908011 补充类图: 注意:1.修改为链接mysql数据库: 2.代码地址:https://github.co ...
- Java中正则Matcher类的matches()、lookAt()和find()的区别<转>
在Matcher类中有matches.lookingAt和find都是匹配目标的方法,但容易混淆,整理它们的区别如下: matches:整个匹配,只有整个字符序列完全匹配成功,才返回True,否则返回 ...
- HDU5886 Tower Defence 【两遍树形dp】【最长链预处理】
题意:N个点的一棵带权树.切掉某条边的价值为切后两树直径中的最大值.求各个边切掉后的价值和(共N-1项). 解法一: 强行两遍dp,思路繁琐,维护东西较多: dis表示以i为根的子树的直径,dis2表 ...