Commute War (Small)
InterviewTime limit5sMemory limit512 MB
Walk the single chain of hourly rides from home to the office, adding each wait, ride time, and geometric checkpoint delay for the expected arrival time.
- Level
Easy3 of 10
- Topics
- Probability, Simulation, Math
- Solved
- No attempts yet
Problem
Yeongsu starts his first job next week. Public transport in Seoul is dense, but every vehicle now has to pass a police checkpoint. To avoid being late on his first day, Yeongsu collected the timetable and the expected delay of every ride on the way to the office. Find the expected time at which he reaches the office.
One ride behaves like this.
- It leaves its origin stop at minute of every hour, that is at times , , , and so on. If Yeongsu is at the origin stop at time , he boards the earliest departure at time or later. A departure exactly at time counts.
- Reaching the destination stop takes minutes.
- The police check the vehicle during the trip. The check itself costs no time, but with probability percent something is wrong and the vehicle is held for minutes. After those minutes the check runs again and can hold the vehicle again with the same probability. The check repeats until it passes. If the check finds a problem times, the trip takes minutes.
- Once aboard, Yeongsu cannot get off before the destination stop.
A ride with never passes the check, so it never reaches its destination stop.
Yeongsu leaves home at time , and at every stop he takes the ride that minimizes the expected arrival time.
Input
The first line has the number of test cases .
The first line of each test case has four integers , , , separated by spaces. is the number of stops, is the number of rides, is the stop where his home is, and is the stop where the office is.
Each of the next lines has six integers , , , , , for one ride. is the origin stop, is the destination stop, is the minute of each hour at which the ride departs, is the travel time, is the length of one delay, and is the probability that a check finds a problem. is a percentage.
Constraints
- for every
- or for every pair , so at most one ride leaves each stop
Output
For each test case print one line in the form Case #x: y, where is the test case number starting at .
If Yeongsu can reach the office, is the expected arrival time rounded to seven digits after the decimal point, with all seven digits printed, so an expectation that is exactly an integer still carries seven zeros after the point. If he cannot reach the office, print -1 in place of , with no decimal point. When the expectation is , so print 0.0000000.