CF11E.Forward, march!

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:64MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or — horror of horrors! — stops for a while. For example, if Jack uses the sequence 'right, left, break', when the sergeant yells: 'Left! Right! Left! Right! Left! Right!', Jack first makes a step with the right foot, then one with the left foot, then he is confused and stops for a moment, then again - this time according to the order - starts with the right foot, then uses the left foot, then - to the sergeant's irritation - he stops to catch his breath, to incorrectly start with the right foot again... Marching this way, Jack will make the step that he is supposed to in the given moment in only one third of cases.

When the officers convinced him he should do something about it, Jack decided to modify the basic sequence of steps that he repeats. However, in order not to get too tired, he has decided that the only thing he'll do is adding any number of breaks in any positions of the original sequence (a break corresponds to stopping for the duration of one step). Of course, Jack can't make a step on the same foot twice in a row, if there is no pause between these steps. It is, however, not impossible that the sequence of steps he used so far is incorrect (it would explain a lot, actually).

Help Private Jack! Given the sequence of steps he keeps repeating, calculate the maximal percentage of time that he can spend marching correctly after adding some breaks to his scheme.

杰克现在已经成为一名士兵了。不幸的是,他在队列训练中遇到了麻烦。按照口令要求,他本应从左脚开始起步,并在每一步之间交替使用双脚,但他却总是重复某个固定的步伐序列——其中有时会踏错脚,甚至更糟的是:中途突然暂停!例如,若杰克采用的步伐序列为“右、左、暂停”,而士官喊出的口令是:“左!右!左!右!左!右!”,那么杰克将首先用右脚迈步,接着用左脚迈步,然后因困惑而暂停片刻;随后(这次按口令顺序)再次从右脚起步,再用左脚迈步,接着又令士官恼火地停下来喘口气,继而又错误地再次从右脚起步……如此行进,杰克仅能在三分之一的情况下,在正确的时间点迈出正确的步伐。

当军官们终于说服他必须对此采取措施时,杰克决定修改自己所重复的基本步伐序列。然而,为了不至于过度疲劳,他决定唯一允许的修改方式是在原始序列的任意位置插入任意数量的“暂停”(一个暂停对应于持续一个步长时间的静止)。当然,若两个连续步伐之间没有暂停,则杰克不能连续两次使用同一只脚迈步。不过,目前他所使用步伐序列本身也有可能是不合法的(这实际上能解释很多问题)。

请帮助列兵杰克!给定他当前不断重复的步伐序列,请计算:在向该序列中添加若干暂停后,他能够以正确步伐行进的最高时间占比。

输入格式

The first line of input contains a sequence consisting only of characters 'L', 'R' and 'X', where 'L' corresponds to a step with the left foot, 'R' — with the right foot, and 'X' — to a break. The length of the sequence will not exceed 106.

输入的第一行包含一个仅由字符 'L'、'R' 和 'X' 组成的序列,其中 'L' 表示用左脚迈步,'R' 表示用右脚迈步,'X' 表示暂停。该序列的长度不超过 10610^6。

输出格式

Output the maximum percentage of time that Jack can spend marching correctly, rounded down to exactly six digits after the decimal point.

输出 Jack 能够正确行进的最长时间占比(百分比),结果向下取整至小数点后恰好六位。

输入输出样例

  • 输入#1

    X

    输出#1

    0.000000
  • 输入#2

    LXRR

    输出#2

    50.000000

说明/提示

In the second example, if we add two breaks to receive LXXRXR, Jack will march: LXXRXRLXXRXRL... instead of LRLRLRLRLRLRL... and will make the correct step in half the cases. If we didn't add any breaks, the sequence would be incorrect — Jack can't step on his right foot twice in a row.

在第二个例子中,如果我们添加两个停顿以得到序列 LXXRXR,则杰克将按如下方式行进:LXXRXRLXXRXRL……,而不是 LRLRLRLRLRLRL……,这样他能在一半的情况下迈出正确的步伐。如果我们不添加任何停顿,该序列将是错误的——杰克无法连续两次用右脚迈步。

输入解题思路,AI测评打分。不知道怎么写?

首页