您的位置:首页 > 其它

数学专项number_theory:UVa 10368

2013-06-28 22:53 260 查看
不难发现每次减的策略只有两种,要么将较大的数对较小的数求余,或者求余之后再加上加上较小的数。如果用dfs暴力搜的话,其递归深度为欧几里得算法的时间复杂度,即较小数的对数,完全可以接受。结果跑了19ms。

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a,b;
int dfs(int a,int b)
{
if(a<b) swap(a,b);
if(a%b==0) return 1;
if(a/b==1) return !dfs(b,a%b);
else return !dfs(a%b+b,b)|!dfs(b,a%b);
}
int main()
{
while(cin>>a>>b)
{
if(!a&&!b) break;
if(dfs(a,b)) cout<<"Stan wins"<<endl;
else cout<<"Ollie wins"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: