http://acm.hdu.edu.cn/showproblem.php?pid=1525
2013-07-19 20:55
330 查看
题目大意是给定两个数a,b,Stan always starts.规则是,每次只能把比较大的数减去比较小的数的整数倍,最后两个数中只要有一个数为0就结束,最后操作了的人为胜。
首先注意条件:当有一个数为0时;当大的数可以整除小的数时,当大的数比小的两倍还大时;就输出;否则继续进行变化;
这里注意下在交换时注意,三个数交换时,必必须中间为(,)见代码:
#include<iostream>
#include<cstdio>
//#include<algorithm>
using namespace std;
int main()
{
int t,n,m,k;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)
break;
k=0;
while(1)
{
if(n<m)
t=n,n=m,m=t;
k++;
if(!m||n/m>=2||!(n%m))
break;
n=n%m;
}
if(k%2)
printf("Stan wins\n");
else
printf("Ollie wins\n");
}
return 0;
}
*********************************************************************************************************
**********************************************************************************************************
方法二;
主要是注意条件:当初我也是条件没弄清楚所以错了好多次:::切记条件找清楚
附上代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int adjust(int maxn,int minn,int s)
{
s++;
if(maxn%minn==0||!minn||maxn/minn>=2)
{
return s;
}
return adjust(max(minn,maxn%minn),min(minn,maxn%minn),s);
}
int main()
{
int n,m,maxn,minn;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)break;
maxn=max(n,m);
minn=min(n,m);
if(maxn%minn==0)
{
printf("Stan wins\n");
continue;
}
int ans=0;
ans=adjust(maxn,minn,ans);
// printf("%d\n",ans);
if(ans%2==1)
{
printf("Stan wins\n");
}
else
printf("Ollie wins\n");
}
return 0;
}
首先注意条件:当有一个数为0时;当大的数可以整除小的数时,当大的数比小的两倍还大时;就输出;否则继续进行变化;
这里注意下在交换时注意,三个数交换时,必必须中间为(,)见代码:
#include<iostream>
#include<cstdio>
//#include<algorithm>
using namespace std;
int main()
{
int t,n,m,k;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)
break;
k=0;
while(1)
{
if(n<m)
t=n,n=m,m=t;
k++;
if(!m||n/m>=2||!(n%m))
break;
n=n%m;
}
if(k%2)
printf("Stan wins\n");
else
printf("Ollie wins\n");
}
return 0;
}
*********************************************************************************************************
**********************************************************************************************************
方法二;
主要是注意条件:当初我也是条件没弄清楚所以错了好多次:::切记条件找清楚
附上代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int adjust(int maxn,int minn,int s)
{
s++;
if(maxn%minn==0||!minn||maxn/minn>=2)
{
return s;
}
return adjust(max(minn,maxn%minn),min(minn,maxn%minn),s);
}
int main()
{
int n,m,maxn,minn;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)break;
maxn=max(n,m);
minn=min(n,m);
if(maxn%minn==0)
{
printf("Stan wins\n");
continue;
}
int ans=0;
ans=adjust(maxn,minn,ans);
// printf("%d\n",ans);
if(ans%2==1)
{
printf("Stan wins\n");
}
else
printf("Ollie wins\n");
}
return 0;
}
相关文章推荐
- http://acm.hdu.edu.cn/showproblem.php?pid=1541
- http://acm.hdu.edu.cn/showproblem.php?pid=1709
- HDU 1702 http://acm.hdu.edu.cn/showproblem.php?pid=1702
- Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
- http://acm.hdu.edu.cn/showproblem.php?pid=1542 矩形面积的并 线段树 + 扫描线 + 离散化
- 找规律。。&&http://acm.hdu.edu.cn/showproblem.php?pid=1097
- http://acm.hdu.edu.cn/showproblem.php?pid=3015 树状数组
- HDU Today&&http://acm.hdu.edu.cn/showproblem.php?pid=2112
- http://acm.hdu.edu.cn/showproblem.php?pid=1003
- http://acm.hdu.edu.cn/showproblem.php?pid=1506
- http://acm.hdu.edu.cn/showproblem.php?pid=1142
- http://acm.hdu.edu.cn/showproblem.php?pid=2717,有所借鉴哦!!
- 寒冰王座(http://acm.hdu.edu.cn/showproblem.php?pid=1248)
- http://acm.hdu.edu.cn/showproblem.php?pid=1124 N!末尾0的个数
- http://acm.hdu.edu.cn/showproblem.php?pid=2866
- http://acm.hdu.edu.cn/showproblem.php?pid=2441 犀利的证明
- http://acm.hdu.edu.cn/showproblem.php?pid=1548
- http://acm.hdu.edu.cn/showproblem.php?pid=2612
- 一个人的旅行(http://acm.hdu.edu.cn/showproblem.php?pid=2066)SPFA||dijkstra
- A C&&http://acm.hdu.edu.cn/showproblem.php?pid=1570