HDU 5640 King's Cake
2016-03-12 21:53
337 查看
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5640
思路:和求最大公约数有点类似
AC代码:
思路:和求最大公约数有点类似
AC代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <map> #include <cstring> #include <climits> #include <cmath> #include <cctype> const int inf = 0x3f3f3f3f;//1061109567 typedef long long ll; using namespace std; int sum; void cf(int n,int m) { if(m == 0) return; if(n == 1 && m == 1) { sum += 1; return; } if(n > m) { swap(n,m); } sum += m / n; cf(n,m%n); } int main() { int t; scanf("%d",&t); while(t--) { sum = 0; int n,m; scanf("%d%d",&n,&m); cf(n,m); printf("%d\n",sum); } return 0; }
相关文章推荐
- Socket编程
- a标签的四个css伪类(link、visited、hover、active)样式理解
- HDU 1253 胜利大逃亡(空间BFS)
- Python的urlopen的使用
- POJ1155 TELE(树形DP)
- JSP内置对象详解
- 求多个数的最小公倍数(以3个数为例)
- 近期编程总结(i think -1)
- Ruby边学边记
- HDU 5640 King's Cake [模拟]
- JavaScript的面向对象
- JSP指令元素
- apache 环境的搭建
- 完全卸载oracle11g步骤
- 今天误用append函数,pythone3.3
- code1044 导弹拦截
- IOS调试—断点调试
- 羊皮书APP(Android版)开发系列(七)Android沉浸通知栏
- 625A.Guest From the Past
- LeetCode 141. Linked List Cycle