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 ...
随机推荐
- JS创建类以及类的方法(StringBuffeer类)
创建StringBuffer类以及toString,append()方法 //创建一个StringBuffer类 ,此类有两个方法:一个是append方法一个是toString方法 function ...
- UVA 10298 Power Strings 字符串的幂(KMP,最小循环节)
题意: 定义a为一个字符串,a*a表示两个字符相连,即 an+1=a*an ,也就是出现循环了.给定一个字符串,若将其表示成an,问n最大为多少? 思路: 如果完全不循环,顶多就是类似于abc1这样, ...
- Java [Leetcode 204]Count Primes
题目描述: Description: Count the number of prime numbers less than a non-negative number, n. 解题思路: Let's ...
- 专题:Windows编译x264、SDL、faac、ffmpeg过程
Windows上编译ffmpeg完整过程,包括编译x264.SDL.faac.在Windows上编译ffmpeg需要用MinGW+msys,本专题用于记录编译过程中遇到的各种问题及解决方法,转载请注明 ...
- 【转】android 自定义控件 使用declare-styleable进行配置属性(源码角度)
原文网址:http://blog.csdn.net/vipzjyno1/article/details/23696537 最近在模仿今日头条,发现它的很多属性都是通过自定义控件并设定相关的配置属性进行 ...
- MySQL基础之第5章 操作数据库
假设已经登录 mysql-h localhost -uroot -proot 5.1.显示.创建.删除数据库 show databases; 显示所有的数据库 create database ...
- C# C/S 结构操作Ini系统文件
Winfrom 开发时,有时会将一些系统某个设置保存到Ini 类型的文件中.下面提供操作Ini 文件的代码: public static class IniFiles { [DllImport(&qu ...
- [Papers]NSE, $\p_3u$, multiplier spaces [Guo-Gala, ANAP, 2013]
$$\bex \p_3\bbu\in L^\frac{2}{1-r}(0,T;\dot X_r(\bbR^3)),\quad 0\leq r\leq 1. \eex$$
- Android应用启动时间及启动日志获取方法
1. Android应用中,可以使用如下方式进行应用启动时间的查看 2. 启动日志获取方法:
- 差分信号(Differential Signal)
差分信号(Differential Signal)在高速电路设计中的应用越来越广泛,电路中最关键的信号往往都要采用差分结构设计,什么另它这么倍受青睐呢?在 PCB 设计中又如何能保证其良好的性能呢? ...