hdu 1525 Euclid's Game (博弈规律)
2016-07-29 20:38
411 查看
Euclid’s Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2836 Accepted Submission(s): 1296
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.
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 12
15 24
0 0
Sample Output
Stan wins
Ollie wins
题意:两个人玩游戏,有两个数,每次可以选择用较大的数减去较小的数的倍数,谁使其出现0谁赢
思路:可以得出,两个人必然会有面对 b,a这种局面的,其中b为较大数,a为较小数,b/a<2,然后他们只有一次一次的减,此时,可以判断奇偶来得出胜负,然后分析初始局面如果是b/a>=2,当面临b/a<2的局面注定失败的时候,先手可以选择直接选择使后手面临此局面,当面临b/a<2的局面注定胜利的时候,先手选择使后手面临(b+a)/a=2的局面,那么后手只能选择让先手面临b/a<2的局面,所以谁面临b/a>=2谁赢,而且谁面临b%a=0的时候直接减完就赢了.
ac代码:
/* *********************************************** Author : AnICoo1 Created Time : 2016-07-29-16.42 Friday File Name : D:\MyCode\2016-7月\2016-7-29.cpp LANGUAGE : C++ Copyright 2016 clh All Rights Reserved ************************************************ */ #include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<set> #include<map> #include<queue> #include<vector> #include<iostream> #include<algorithm> #define MAXN 1010000 #define LL long long #define ll __int64 #define INF 0xfffffff #define mem(x) memset(x,0,sizeof(x)) #define PI acos(-1) #define eps 1e-8 using namespace std; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;} double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;} //head int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF,n||m) { if(n>m) swap(n,m); int cnt=0,a=n,b=m; while(a) { if(b%a==0||b/a>=2) break; int t=a;a=b-a;b=t; cnt++; } if(cnt%2==0) printf("Stan wins\n"); else printf("Ollie wins\n"); } return 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【博弈 PN找规律】
- 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 || poj 2348 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 博弈