TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

The subway in Stockholm consists of several subway lines. In this problem we will consider one line
in particular, and the problems that quite often happens on it when there’s been a “signalling error”.


A subway line can be seen as two parallel rails connected at the endpoints. In the upper rail the trains
are going from right to left and in the lower rail the trains are going from left to right. When a train
reaches an endpoint of a rail, it switches to the opposite rail and changes direction. This switch is
instantaneous and takes no time.


During normal traffic, the traffic flow is continuous and the trains are moving at a constant speed (1
length unit per time unit). The trains are evenly distributed; that is, at any given position on a rail, the
trains will appear periodically. We will assume that the time it takes for a train to stop and pick up
passengers is negligible.


Now, because of signalling errors, the trains have been randomly distributed along the line. Your job
as the traffic manager is to, as fast as possible, ensure that the trains will be evenly distributed along
the line again. Write a program that, given the current train positions, calculates how fast this can be
achieved. You are allowed to order the trains to temporarily stop, and/or change direction anywhere
along the line. If a train changes direction, it will move from one rail to the other.



Figure 1: Both rails have the length 100. In the upper example the trains are positioned at 5 (direction
right), 35 (left), 46 (left), 75 (left) and 85 (right). One way to make the trains evenly distributed is for
the train at position 46 to travel one unit to the left and then change direction. This takes one time
unit. However, this is not the optimal solution; see Example 1 below.

Input Format

There are multiple test cases in the input file. For each test case:


The input is read from standard input. The first line in the input contains two integers separated by a
single space, the length m of the subway rails, and the number n of trains on the line. Then follows n
lines each describing the current position of a train. This will be given as an integer xi and a direction
(L for left, R for right), separated by a single space.


100<=m<=100,000,000

1<=n<=100,000

0<=xi<=m

Output Format

Your program should output a single line to standard output, containing the shortest time it takes to
make the trains evenly distributed.
請輸出至小數點以下兩位

Sample Input 1

100 5
5 R
35 L
46 L
75 L
85 R

100 8
9 L
15 R
41 L
33 L
81 R
33 R
100 L
97 R

Sample Output 1

0.50
15.50

Hints

Problem Source

Migrated from old NTUJ.

BOI2009

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200