#P10951. 最优高铁环
最优高铁环
Background
Phantom Country has built the most advanced high-speed rail system in the world. Its trains are divided into the following types:
- —high-speed photon-powered train—speed
- —high-speed EMU—speed
- —EMU set—speed
- —express—speed
- —fast—speed
A train service number starts with one of the letters above, followed by a positive integer .
Background
Phantom Country has built the most advanced high-speed rail system in the world. Its trains are divided into the following types:
- —high-speed photon-powered train—speed
- —high-speed EMU—speed
- —EMU set—speed
- —express—speed
- —fast—speed
A train service number starts with one of the letters above, followed by a positive integer .
Problem Description
Because the terrain of the country is uneven, the suitable operating speed of railways differs from place to place.
Therefore, each travel route in the country consists of train services.
For example, when , one route is: .
When the last service of one route is the same as the first service of another route, these two routes can be connected into a longer travel route.
Obviously, connecting several routes may form a cycle.
If there are travel routes as follows:
The speeds of services are , respectively.
Define the value of a high-speed rail cycle as the average of (the sum of speeds on each travel route in the cycle), i.e.:
The maximum value among all high-speed rail cycles is called the value of the optimal high-speed rail cycle.
Given travel routes, find the value of the optimal high-speed rail cycle.
Input Format
The first line contains the number of travel routes .
The next lines each contain one travel route, consisting of several train services separated by -. The numbering rule of train services is as described above.
The input is guaranteed to be valid.
Output Format
Output the value of the optimal high-speed rail cycle, rounded to the nearest integer.
If no such cycle exists, output .
3
T120-D135-S1
S1-G12
G12-K856-T120
1283
Hint
Sample Explanation
$\dfrac{(200+300+1000)+(1000+500)+(500+150+200)}3=1283$
Constraints
For of the testdata, .
For of the testdata, , and the number of train services in each travel route does not exceed .
The input is large. Please use read and scanf. The testdata does not guarantee that using cin will pass within the time limit.
To avoid precision issues, please use double. The testdata guarantees that the result does not exceed .
Translated by ChatGPT 5