xiaoguozi's Blog
Pay it forword - 我并不觉的自豪,我所尝试的事情都失败了······习惯原本生活的人不容易改变,就算现状很糟,他们也很难改变,在过程中,他们还是放弃了······他们一放弃,大家就都是输家······让爱传出去,很困难,也无法预料,人们需要更细心的观察别人,要随时注意才能保护别人,因为他们未必知道自己要什么·····

 http://acm.hdu.edu.cn/showproblem.php?pid=1525

 1 //题意: 给定n,m两个数,两个人轮流操作:
 2 //选m,n小的数,每次都是大的减去小的数的k倍,k<=max(n,m)/min(n,m);
 3 //知道其中一个为0时,执行该操作的为胜者
 4 
 5 //Analyse:for example: if n>m,then n=m*k+c(k<=n/m,c=n%m)
 6 //if k>1,then the first player can decide who'll win.if current statue is lost,he can decrease (k-1)*m,
 7 //the statue is changed to (m+c,m),the second player only operate m,so the statue is changed to (m,c) which
 8 //is the winning statue. if current is the winning statue,he can decrease k*m,the statue is changed to (m,c)
 9 //which is the lost statue.So if k>1,the one who operate it is the winner,he is active.but if k==1,he can only
10 //operate the small one.the one who first meet k>1 is the winner.specially,if no one meet k>1,the player operate
11 //it in turn,the first makes the n or m to zero is the winner.
12 #include <iostream>
13 
14 using namespace std;
15 int main()
16 {
17     int n,m;
18     while(cin>>n>>m,n+m){
19         int cnt=0;
20         int ans=0;
21         while(1){
22             if(n<m)swap(n,m);
23             ans=n/m;
24             if(ans>=2){
25                 break;
26             }
27             cnt++;
28             n%=m;
29             if(n==0){
30                 cnt++;
31                 break;
32             }                
33         }
34         if(cnt&1){
35             cout<<"Ollie wins\n";
36         }
37         else cout<<"Stan wins\n";
38     }
39     return 0;
40 }
posted on 2008-07-23 18:55 小果子 阅读(251) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理