UVa 10077 - The Stern-Brocot Number System
来源:互联网 发布:网络直播十大灵异事件 编辑:程序博客网 时间:2024/04/26 15:10
题目:给你一颗分数组成的二叉树,初始值是1/1,两边的边界分别是0/1与1/0,然后递归建立子树节点,
每个子树的节点值为两边的边界值得分子之和比上分母之和,新的值也加入边界值。
分析:递归,数据结构。看到上面的描述就可以做了吧,直接递归。
tree(L, R, key) {
if(add(L+R)= key)return;
if(add(L+R)< key){
cout << "R";
tree(L,add(L,R),key);
}else {
cout << "L";
tree(add(L,R),R,key);
}
}
说明:强大的递归╮(╯▽╰)╭。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;void tree(int Lx, int Ly, int Rx, int Ry, int Tx, int Ty) {if (Lx+Rx == Tx && Ly+Ry == Ty) {printf("\n");return;}if ((Lx+Rx)*Ty < (Ly+Ry)*Tx) {printf("R");tree(Lx+Rx, Ly+Ry, Rx, Ry, Tx, Ty);}else {printf("L");tree(Lx, Ly, Lx+Rx, Ly+Ry, Tx, Ty);}}int main(){int n,m;while (cin >> n >> m && !(m == 1 && n == 1))tree(0, 1, 1, 0, n, m); return 0;}
0 0
- UVa 10077 - The Stern-Brocot Number System
- uva 10077 The Stern-Brocot Number System
- UVA 10077 The Stern-Brocot Number System
- UVa Problem 10077 The Stern-Brocot Number System (Stern-Brocot 代数系统)
- UVa Problem Solution: 10077 - The Stern-Brocot Number System
- UVa 10077 The Stern-Brocot Number System (数学)
- 10077 - The Stern-Brocot Number System
- 110507 The Stern-Brocot Number System
- (挑战编程_5_7)The Stern-Brocot Number System
- The Stern-Brocot Number System(排序二叉树)
- Hdu 6209 The Intersection(Stern-Brocot tree+二分)
- hdu 4556 Stern-Brocot
- hdu4556-Stern-Brocot Tree
- hdu4556-Stern-Brocot Tree
- HDU-4556-Stern-Brocot Tree
- hdu 4556 Stern-Brocot Tree
- hdu 4556 Stern-Brocot Tree
- HDOJ 4556 Stern-Brocot Tree
- IPv4学习笔记
- java 中的数据结构
- MFC列表控件(ListControl)
- 游标的概念和作用
- 使用.htaccess 开启gzip 缓存文件 网页 提高速度 和 .htaccess文件用法集锦
- UVa 10077 - The Stern-Brocot Number System
- js贪吃蛇
- iOS开发技巧-模拟器simulator添加图片
- Thread与Handler总结
- 【转载】数据库设计原则
- HDU 5192 [迷之WA!]
- java 验证邮箱格式正确性、验证字符串是否为数字
- 安装unbuntu
- hdu 1717 小数化分数2(数学)