hdu 1525 Euclid's Game 博弈
来源:互联网 发布:南京江北新区网络问政 编辑:程序博客网 时间:2024/05/23 15:06
Euclid's Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2591 Accepted Submission(s): 1170
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
Source
University of Waterloo Local Contest 2002.09.28
结果花了很长时间无果。后来觉得似乎不能直接得出公式,但是对于每种情形的处理方式可以得出。
对于两个数a,b
令a<=b
如果b>=2*a,先手必胜
如果b==a,先手必胜
否则转化为问题(b-a,a)的反结果
(打表找真理)
/**========================================== * This is a solution for ACM/ICPC problem * * @source£ºhdu 1525 * @type: * @author: wust_ysk * @blog: http://blog.csdn.net/yskyskyer123 * @email: 2530094312@qq.com *===========================================*/#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>using namespace std;typedef long long ll;bool work(ll a,ll b){ if(b>=2*a) return true; if(b==a) return true; return !work(b-a,a);}int main(){ ll a,b; while(~scanf("%lld%lld",&a,&b)&&(a||b)) { if(a>b) swap(a,b); puts(work(a,b)?"Stan wins":"Ollie wins"); } 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 找规律博弈
- Spring Security安全框架入门篇
- 最简单的基于FFmpeg的推流器(以推送RTMP为例)
- c# 写入数据到excel文件
- nyoj263 精挑细选
- 枉法裁判罪
- hdu 1525 Euclid's Game 博弈
- setScale,preScale和postScale的区别
- POJ 2481Cows
- 51nod1006最长公共子序列Lcs问题
- 杭电1060 Leftmost Digit
- 构建一个Struts2项目
- C#DateTime各种使用
- 最简单的基于FFMPEG的推流器附件:收流器
- uoj#35. 后缀排序 后缀数组