数学专项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; }
相关文章推荐
- 数学专项number_theory:UVa 11105
- 数学专项number_theory:UVa 10692
- 数学专项number_theory:UVa 10236
- 数学专项number_theory:UVa 10951
- 数学专项number_theory:UVa 294
- 数学专项number_theory:UVa 10162
- 数学专项number_theory:UVa 11728
- 数学专项number_theory:UVa 756
- 数学专项number_theory:UVa 10515
- 数学专项number_theory:UVa 11768
- 数学专项number_theory:UVa 10622
- 数学专项number_theory:UVa 10090
- 数学专项number_theory:UVa 10127
- 数学专项number_theory:UVa 718
- 数学专项number_theory:UVa 10539
- 数学专项number_theory:LA 4382
- 数学专项number_theory:LA 2955
- 数学专项number_theory:LA 4079
- 数学专项game_theory:UVa 11927
- 数学专项game_theory:UVa 12293