Two Snails
Time limit2sMemory limit256 MB
Two snails crawl up and slide down on a 12-hour day/night cycle; find the total time over z hours when the first snail is higher than the second.
- Level
Medium4 of 10
- Topics
- Math, Simulation, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
Vasya sat by a window and noticed two snails on a pole, crawling upward. Vasya began watching them. He noticed that in one hour the first snail climbs centimeters and the second snail climbs centimeters.
The next morning Vasya noticed that the snails were lower than they had been in the evening. He realized that during the night the first snail slides down centimeters per hour and the second snail slides down centimeters per hour.
hours passed since the start of the observation, and Vasya wondered: during what period of time was the first snail higher than the second over these hours?
Vasya decided to assume that the snails move at their respective constant speeds both day and night, and that day and night each last 12 hours. The observation started at the beginning of the day, when the snails were at the same height. The height of the pole and the initial positions of the snails are such that the snails never leave the bounds of the pole.
Input
The first line contains a positive integer (), the number of test cases in the input. The descriptions of the test cases follow.
Each test case contains five positive integers , , , , and (, ), the speeds of the snails and the time period Vasya is interested in.
The sum of over all test cases is guaranteed not to exceed .
Output
Output lines. For each test case, output a single real number , the time during which the first snail was higher than the second. Print each number on its own line. All numbers must be printed with an absolute or relative error of at most .
Note that printing long double values in C++ does not work correctly in the compiler version used by the judges. We apologize and will try to fix this as soon as possible, but for now we recommend using the double type.