[poj2348]Euclid's Game(鍗氬紙璁?gcd)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[poj2348]Euclid's Game(鍗氬紙璁?gcd)相关的知识,希望对你有一定的参考价值。

鏍囩锛?/p>

Euclid鈥榮 Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9033   Accepted: 3695

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

Source

 
 
鑰佸笀鐨勬儕澶╂ā鎷熻禌#1
 
TAT鎴戝ぉ鐪熺殑浠ヤ负鎴戜細杩欓亾棰樹簡
寰堝鏄撴兂鍒板浜庝袱鍫嗘暟瀛楋紝鍙湁涓ょ鍐崇瓥锛氭嬁涓€涓垨鑰呮嬁澶氫釜
瀵逛簬a>b涓攁<2*b鐨勬儏鍐碉紝鍙兘鎷夸竴绉嶏紝鍥犳鍙互纭畾鍏堝悗鎵?/div>
褰撳彲浠ユ嬁澶氭鏃讹紝瑕佷箞鍏ㄥ彇璧拌兘鍙栬蛋鐨勶紝瑕佷箞鍐嶇暀涓嬩竴娆¤兘鍙栫殑閲?/div>
鎵€浠ュ涓や釜鏁板仛涓€娆cd
姣忔鍙栨ā鍓嶅垽鏂彲浠ュ彇鍑犳鏁板瓧锛屽緱鍒颁竴涓簭鍒椾粎鍖呭惈1鍜?
(鎴戝彧鎯冲埌杩欓噷)
(璇濊璁插崥寮堣鐨勬椂鍊欐垜濂藉儚鐫$潃浜嗘€笉寰?
瀵逛簬杩炵画鐨?锛屽彲浠ョ珛鍒诲垽鏂粨灏惧厛鎵嬭繕鏄悗鎵?/div>
浣嗗浜庝竴涓?锛屽彧瑕佹湁涓€鏂归亣鍒颁簡2锛屼粬灏卞彲浠ユ搷绾靛眬鍔?/div>
鍗冲湪2缁撴潫鍚庯紝浠栦竴瀹氬彲浠ヨ鑷繁浣嶄簬搴忓垪缁撳熬鎴栦笅涓€涓?
閭d箞鍦╣cd鐨勬椂鍊欙紝鍙渶璁板綍鍑虹幇绗竴涓?鐨勬椂鍊欐槸鍏堟墜杩樻槸鍚庢墜鍗冲彲
鎶€鏈垎浜? id=
 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define LL long long
 6 int main(){
 7     int tmp,n,m,pl;
 8     while(scanf("%d %d",&n,&m)!=EOF&&(n&&m)){
 9         pl=0;
10         while(n&&m){
11             if(m<n){tmp=m;m=n;n=tmp;}
12             if((n<<1)>0&&m>=(n<<1))break;
13             m=m%n;
14             if(!m)break;
15             pl^=1;
16         }
17         if(!pl)puts("Stan wins");
18         else puts("Ollie wins");
19     }
20     return 0;
21 }
View Code

 

以上是关于[poj2348]Euclid's Game(鍗氬紙璁?gcd)的主要内容,如果未能解决你的问题,请参考以下文章

POJ 2348 Euclid's Game 博弈论

poj2348 Euclid's Game

POJ - 2348 Euclid's Game(博弈论入门题)

POJ 2348 Euclid's Game(博弈)题解

POJ 2348 Euclid's Game(辗转相除博弈+自由度分析)

Euclid's Game