当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3556:Continued Fraction

题目描述
Dumbear loves numbers very much.
One day Dumbear found that each number can be expressed as a continued fraction. See below.

Formally, we say a number k can be expressed as a continued faction if

where a0, a1, …, an are positive integers except that a0 maybe be 0 and an cannot be 1.
Dumbear also found a sequence which looks like the Farey sequence. Initially the sequenceand if we insert an elementbetween all the two adjacent element,in Di, then we get a sequence Di+1. So you can seeandAssume initially you are on the elementin D0, and if now you are on the element k in Di, then if you go left(‘L’)(or right(‘R’)) you will be on the left(or right) element of k in Di+1. So a sequence composed of ‘L’ and ‘R’ denotes a number. Such as ‘RL’ denotes the number

Now give you a sequence composed of ‘L’ and ‘R’, you should print the continued fraction form of the number. You should use ‘-‘ to show the vinculum(the horizontal line), you should print one space both in front and back of ‘+’, and all parts up or down the vinculum should be right aligned. You should not print unnecessary space, ‘-‘ or other character. See details in sample.
输入解释
There are several test cases in the input.
For each test case, there is a single line contains only a sequence composed of ‘L’ and ‘R’. The length of the sequence will not exceed 10000.
The input terminates by end of file marker.
输出解释
For each test case, output the continued fraction form of the number which the input sequence denotes. The total amount of output will not exceed 4MB.
输入样例
LR
RL
输出样例
        1 
0 + ----- 
        1
    1 + -
        2
    1
1 + -
    2
来自杭电HDUOJ的附加信息
Author Dumbear@WHU
Recommend zhouzeyong

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3556

最后修改于 2020-10-25T23:04:41+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 131072/65536K(Java/Others)