hdu 1525 Euclid's Game 博弈
来源:互联网 发布:json.stringify()使用 编辑:程序博客网 时间:2024/05/29 17:40
Euclid's Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3987 Accepted Submission(s): 1898
Problem Description
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.
25 7
11 7
4 7
4 3
1 3
1 0
an Stan wins.
Input
The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.
Output
For 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 1215 240 0
Sample Output
Stan winsOllie wins题意: 给你两个数 每次大的数可以减掉小的数的整数倍 知道一个人面临其中一个数为0 的情况那么则为输。。思路: 比赛的时候一直想枚举某一个状态的后继 如果他的后继中有一个为输的状态 那么他一定为赢的状态 如果一个状态的后继全部是赢的状态 那么他一定是输的状态 ,但是对比较大的数 那么枚举就会很困难。。在这里我们注意到 两个数 max 和 min 能转移到的状态 ,如果max%min ==0 那么一定为赢的状态如果 min ==0 那么一定为输的状态然后对于max/min>=2 的状态 他一定一定一定会转移到 min max%min 的状态 因为min max%min 的状态是可以确定为赢还是输的状态 而对于先手就可以决定是将 min max%min 状态留给自己还是对手 。对于max/min>=1 且小于2的情况那么就只有一种转移情况了 就只能转移到 max-min min 的状态。。代码:#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;int maxx,minn;int main(){ int t1,t2; while(cin>>t1>>t2) { if(t1==0&&t2==0) break; maxx=max(t1,t2); minn=min(t1,t2); int cnt=1; while(1) { if(minn==0||maxx%minn==0||maxx/minn>=2) break; cnt++; //printf("%d %d\n",minn,maxx); t1=minn; t2=maxx-minn; maxx=max(t1,t2); minn=min(t1,t2); } if(cnt%2) printf("Stan wins\n"); else printf("Ollie wins\n"); } return 0;}
阅读全文
0 0
- HDU 1525 Euclid's Game (博弈)
- hdu 1525 Euclid's Game 博弈
- [简单博弈] hdu 1525 Euclid's Game
- hdu 1525 Euclid's Game 博弈
- HDU 1525 Euclid's Game 博弈
- HDU 1525 Euclid's Game (博弈)
- HDU 1525 Euclid's Game 博弈
- hdu 1525 Euclid's Game 博弈
- HDU 1525 Euclid's Game(博弈)
- hdu 1525 Euclid's Game (博弈规律)
- HDU 1525 Euclid's Game (博弈)
- HDU 1525 Euclid's Game (博弈)
- HDU 1525 Euclid's Game(博弈)
- hdu 1525 Euclid's Game 博弈
- hdu 1525 Euclid's Game 博弈~~需要分析一下
- HDU 1525 Euclid's Game (博弈、找规律)*
- HDU 1525 Euclid's Game【博弈 PN找规律】
- HDU 1525 Euclid's Game 找规律博弈
- Toy Storage POJ
- Android 调用相机拍照时报错FileUriExposedException .jpg beyond app through Intent.getData()
- Oracle 11g数据库详细安装步骤图解
- JAVA实现图片加水印及Base64图片字符串加水印
- 免费Git服务器
- hdu 1525 Euclid's Game 博弈
- 一、实现欢迎界面和游戏背景图的滚动(雷霆战机)
- PAT
- 二、设计飞机类,实现键盘移动(雷霆战机)
- 总结android应用内存泄漏的问题,及需要注意的地方
- Android 7.0与6.0多语言效果对比以及遇到的坑
- 三、使用鼠标控制飞机,实现风骚走位(雷霆战机)
- 四、子弹类的创建,飞机子弹发射与无用子弹的销毁(雷霆战机)
- Zookeeper系列—Linux下的安装