zoukankan      html  css  js  c++  java
  • 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
    ", f(a, b));
    
        }
        return 0;
    }
    

      

  • 相关阅读:
    Qt中widget重新setParent需要注意的问题
    在有状态机下,写自动测试需要注意的问题
    C#获取当前路径的7种方法
    VS快捷键大全
    [WPF]设置背景色
    [WPF]建立自适应窗口大小布局的WinForm窗口
    [WPF]Slider控件常用方法
    [C#.NET]
    VB中的API详解
    VB6.0和VB.Net的函数等对照表
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5774465.html
Copyright © 2011-2022 走看看