LA 7363 A Rational Sequence (binary tree)

Source: Internet
Author: User

Test instructions: Given a binary tree, and numbering and stipulating each one, now give you a value that asks you what the first few.

Analysis: This problem, I think for a long time to come out, this is really the data structure is too poor, not solid enough, this problem, should be pushed from the bottom up, if the numerator is greater than the denominator, then this number is odd,

To add 1, if it is less than, do not add. Just push on to the first one.

The code is as follows:

#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 I  NF = 0x3f3f3f3f3f3f;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int maxn = ten + 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) + 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;}

  

LA 7363 A Rational Sequence (binary tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.