UVaLive 7363 A Rational Sequence (二叉树)
题意:给定一个二叉树,并对每一个进行编号和规定,现在给你一个值,问你是第几个。
析:这个题,我想了好久才想出来,这个真是数据结构练的太差了,不够扎实,这个题,应该从下向上推,如果分子大于分母,那么这个编号就是奇数,
要加上1,如果是小于,就不用加.推到第一个就好。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10 + 5;
const int mod = 1e9;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} LL f(LL a, LL b){
if(a == b) return 1;
if(a < b) return f(a, b-a) * 2;
if(a > b) return 2 * f(a-b, b) + 1;
} int main(){
int T; cin >> T;
while(T--){
LL a, b;
scanf("%d %lld/%lld", &m, &a, &b);
printf("%d ", m);
printf("%lld\n", f(a, b)); }
return 0;
}
UVaLive 7363 A Rational Sequence (二叉树)的更多相关文章
- 【规律】A Rational Sequence
题目描述 An infinite full binary tree labeled by positive rational numbers is defi ned by:• The label of ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] 298. Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] 549. Binary Tree Longest Consecutive Sequence II 二叉树最长连续序列之 II
Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree. Especia ...
- [LintCode] 619 Binary Tree Longest Consecutive Sequence III 二叉树最长连续序列 III
Given a k-ary tree, find the length of the longest consecutive sequence path. The path could be star ...
- [LeetCode] 128. Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- Live Archive 训练题
7091 Height Ordering Mrs. Chambers always has her class line up in height order (shortest at the fro ...
- ※数据结构※→☆非线性结构(tree)☆============二叉树 顺序存储结构(tree binary sequence)(十九)
二叉树 在计算机科学中,二叉树是每个结点最多有两个子树的有序树.通常子树的根被称作“左子树”(left subtree)和“右子树”(right subtree).二叉树常被用作二叉查找树和二叉堆或是 ...
- [LeetCode] Binary Tree Longest Consecutive Sequence II 二叉树最长连续序列之二
Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree. Especia ...
随机推荐
- uva12230Crossing Rivers
数学期望. 过每条河的时间的可能在[L/v,3*L/v]间均匀分布,数学期望为2*L/v. 然后在加上在陆上走的时间. #include<cstdio> #include<algor ...
- wince和window mobile winphone
windows mobile是微软在2000年左右推出的针对移动平台的操作系统,这个系统一直使用到三年前,微软开始启用metro界面,将windows mobile改名为windows phone. ...
- Android PRODUCT_COPY_FILES 自动拷贝文件
/********************************************************************** * Android PRODUCT_COPY_FILES ...
- python中的类和实例
今天花了两个多小时后搜索相关博客看了看python中有关类和实例的介绍,差不多大概明白了. python中的类和c++中的类是一样的,不同之处就是c++的类,如果含有成员变量,并且成员变量发生变化后, ...
- (转)HTTP协议详解
引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...
- Android启动activity的4种模式(standard、singleTop、singleTask、singleINstance)
在AndroidManifest.xml中配置activity时,android:launchMode属性会指定启动activity的模式,有四种: standard singleTop single ...
- Egret应用开发实践(01) Egret与WebPack
Egret Egret引擎是一款使用TypeScript语言构建的开源免费的移动游戏引擎.Egret仅是纯粹的使用TypeScript语言来开发游戏,开发后可以使用Egret来打包为HTML5网页游戏 ...
- android view的setVisibility方法值的意思
android view的setVisibility方法值的意思 有三个值 visibility One of VISIBLE, INVISIBLE, or GONE. 常量值为0,意思是可见的 常 ...
- MVC ActionResult -- JavaScriptResult,JsonResult
以下是ActionResult的继承图: 大概的分类: EmptyResult:表示不执行任何操作的结果 ContentResult :返回文本结果 JavaScriptResult:返回结果为Jav ...
- hdu 1198 Farm Irrigation
令人蛋疼的并查集…… 我居然做了大量的枚举,居然过了,我越来越佩服自己了 这个题有些像一个叫做“水管工”的游戏.给你一个m*n的图,每个单位可以有11种选择,然后相邻两个图只有都和对方连接,才判断他们 ...