[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):
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 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>
View Code
鍗冲湪2缁撴潫鍚庯紝浠栦竴瀹氬彲浠ヨ鑷繁浣嶄簬搴忓垪缁撳熬鎴栦笅涓€涓?
閭d箞鍦╣cd鐨勬椂鍊欙紝鍙渶璁板綍鍑虹幇绗竴涓?鐨勬椂鍊欐槸鍏堟墜杩樻槸鍚庢墜鍗冲彲
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 }
以上是关于[poj2348]Euclid's Game(鍗氬紙璁?gcd)的主要内容,如果未能解决你的问题,请参考以下文章
POJ - 2348 Euclid's Game(博弈论入门题)