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)