UVaLive 7363 A Rational Sequence (二叉树)

时间:2022-10-06 14:42:22

题意:给定一个二叉树,并对每一个进行编号和规定,现在给你一个值,问你是第几个。

析:这个题,我想了好久才想出来,这个真是数据结构练的太差了,不够扎实,这个题,应该从下向上推,如果分子大于分母,那么这个编号就是奇数,

要加上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 (二叉树)的更多相关文章

  1. 【规律】A Rational Sequence

    题目描述 An infinite full binary tree labeled by positive rational numbers is defi ned by:• The label of ...

  2. &lbrack;LeetCode&rsqb; Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  3. &lbrack;LeetCode&rsqb; 298&period; Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  4. &lbrack;LeetCode&rsqb; 549&period; 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 ...

  5. &lbrack;LintCode&rsqb; 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 ...

  6. &lbrack;LeetCode&rsqb; 128&period; Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  7. Live Archive 训练题

    7091 Height Ordering Mrs. Chambers always has her class line up in height order (shortest at the fro ...

  8. ※数据结构※&srarr;&star;非线性结构(tree)&star;&equals;&equals;&equals;&equals;&equals;&equals;&equals;&equals;&equals;&equals;&equals;&equals;二叉树 顺序存储结构(tree binary sequence)(十九)

    二叉树 在计算机科学中,二叉树是每个结点最多有两个子树的有序树.通常子树的根被称作“左子树”(left subtree)和“右子树”(right subtree).二叉树常被用作二叉查找树和二叉堆或是 ...

  9. &lbrack;LeetCode&rsqb; Binary Tree Longest Consecutive Sequence II 二叉树最长连续序列之二

    Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree. Especia ...

随机推荐

  1. Swift 2&period;x -&gt&semi; Swift 3&period;0

    Swift 3.0 相对于 2.x 有很大变化.特别是因为命名习惯的改变,导致许多 Api 都发生了变化.总的趋势是让表示更简洁. 对旧的代码升级,大部分可以根据提示来进行更正.但也有的需要手动修改. ...

  2. 查询数据库表大小sql

    SELECT a.name, b.rowsFROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.idWHERE (a.type = ' ...

  3. &lbrack;moka同学笔记&rsqb;yii2&period;0数据库操作以及分页

    1.model中models/article.php 1 <?php 2 3 namespace app\models; 4 5 use Yii; 6 7 /** 8 * This is the ...

  4. URAL 2048 History 蔡勒公式

     HistoryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...

  5. Intervals(差分约束)

    http://poj.org/problem?id=1201 题意:给出N个整数区间[ai,bi],并且给出一个约束ci,( 1<= ci <= bi-ai+1),使得数组Z在区间[ai, ...

  6. &lbrack;BZOJ1552&rsqb; &lbrack;Cerc2007&rsqb; robotic sort &lpar;splay&rpar;

    Description Input 输入共两行,第一行为一个整数N,N表示物品的个数,1<=N<=100000.第二行为N个用空格隔开的正整数,表示N个物品最初排列的编号. Output ...

  7. D3算法编写决策树

    前言 所谓构建决策树, 就是递归的对数据集参数进行“最优特征”的选择.然后按最优特征分类成各个子数据集,继续递归. 最优特征的选择:依次计算按照各个特征进行分类以后数据集的熵,各个子数据集的熵比较后, ...

  8. Android中弹出dialog后无法捕捉back键

    一.需求 在Android开发过程中,弹出dialog后无法捕捉back键,点击back按键无响应. 二.解决方案 原因:弹出dialog后,activity失去焦点,dialog获得当前焦点. 解决 ...

  9. Python常用库之functools

    functools 是python2.5被引人的,一些工具函数放在此包里. python2.7中 python3.6中 import functools print(dir(functools)) [ ...

  10. 安全测试6&lowbar;Web安全工具第三节(Web安全工具)

    之前学习了下安全工具前的一些基础知识,今天来学习下安全工具,这些工具是python写的. 1.敏感文件探测入门: 敏感文件探测的原理如下: 一般探测敏感文件我们都是借助工具扫描,这里我给大家推荐一个简 ...