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;
    }
    

      

  • 相关阅读:
    冒泡排序的java实现
    linux磁盘挂载
    Spring第九篇:primary指定bean为首选对象
    Spring第八篇:容器中bean对象的创建顺序
    Spring第六篇:依赖的手动注入
    Spring第五篇:Spring bean的作用域
    Spring第四篇:bean实例的创建方式
    SpringBoot 整合 kaptcha 验证码
    Java 创建线程池的方式
    MySQL IF() 函数用法
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5774465.html
Copyright © 2011-2022 走看看