21843_Birdtree

2022-5-16 18:20| 发布者: Hocassian| 查看: 24| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505894598100-Problem List-采集的数据-后羿采集器.html

Pro.ID

21843

Title

Bird tree

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21843

AC

3

Submit

3

Ratio

100.00%

时间&空间限制

  • Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    The Bird tree is an infinite binary tree, whose first 5 levels look as follows:

    It can be defined as follows:

    This is a co-recursive definition in which both occurrences of bird refer to the full (infinite) tree. The expression bird + 1 means that 1 is added to every fraction in the tree, and 1/bird means that every fraction in the tree is inverted (so a/b becomes b/a).

    Surprisingly, the tree contains every positive rational number exactly once, so every reduced fraction is at a unique place in the tree. Hence, we can also describe a rational number by giving directions (L for left subtree, R for right subtree) in the Bird tree. For example, 2/5 is represented by LRR. Given a reduced fraction, return a string consisting of L's and R's: the directions to locate this fraction from the top of the tree.

    输入

    On the first line a positive integer: the number of test cases, at most 100. After that per test case:

    • one line with two integers a and b ( 1 ≤ a, b ≤ 109 ), separated by a '/'. These represent the numerator and denominator of a reduced fraction. The integers a and b are not both equal to 1, and they satisfy gcd(a, b) = 1.

    For every test case the length of the string with directions will be at most 10000.

    输出

    Description

    The Bird tree is an infinite binary tree, whose first 5 levels look as follows:

    It can be defined as follows:

    This is a co-recursive definition in which both occurrences of bird refer to the full (infinite) tree. The expression bird + 1 means that 1 is added to every fraction in the tree, and 1/bird means that every fraction in the tree is inverted (so a/b becomes b/a).

    Surprisingly, the tree contains every positive rational number exactly once, so every reduced fraction is at a unique place in the tree. Hence, we can also describe a rational number by giving directions (L for left subtree, R for right subtree) in the Bird tree. For example, 2/5 is represented by LRR. Given a reduced fraction, return a string consisting of L's and R's: the directions to locate this fraction from the top of the tree.

    Input

    On the first line a positive integer: the number of test cases, at most 100. After that per test case:

    • one line with two integers a and b ( 1 ≤ a, b ≤ 109 ), separated by a '/'. These represent the numerator and denominator of a reduced fraction. The integers a and b are not both equal to 1, and they satisfy gcd(a, b) = 1.

    For every test case the length of the string with directions will be at most 10000.

    Output

    Per test case:

    one line with the string representation of the location of this fraction in the Bird tree.

    Sample Input

    3
    1/2
    2/5
    7/3

    Sample Output

    L
    LRR
    RLLR

    Source

    样例输入

    3
    1/2
    2/5
    7/3

    样例输出

    L
    LRR
    RLLR

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部