Magical, Marvelous Tour
Time limit5sMemory limit512 MB
Arnar picks a contiguous segment, Solveig claims the largest of the three parts it creates, and Arnar keeps the rest.
- Level
Medium6 of 10
- Topics
- Prefix sum, Two pointers
- Solved
- No attempts yet
Problem
The owner of an electronics factory hid a golden transistor inside seven of her devices. Whoever buys one of those devices is invited to tour the factory.
Arnar and Solveig heard that exactly one device in their local store holds a golden transistor. They pooled their money, bought every device in the store, lined the devices up and numbered them to . Each device holds some number of transistors. Then they agreed on a rule for deciding who keeps the golden transistor.
Arnar first picks a range , both ends included, with . Solveig then picks one group of devices to take.
- If , she may take every device in .
- If , she may take every device in .
- She may always take every device in .
Once Solveig has picked a group, Arnar keeps every device she did not take.
For example, with three devices and Arnar picking , Solveig picks one of , and . If Arnar picks , Solveig picks either or .
The golden transistor is equally likely to be any one of the transistors, so a person's chance of touring the factory is the number of transistors that person keeps divided by the total number of transistors. Both of them pick so that their own chance is as large as possible. Find Arnar's chance of touring the factory.
Input
The first line contains the number of test cases . Each of the next lines contains five integers , , , and . There are devices, and device holds transistors. The devices are numbered to .
Constraints:
- The sum of over all test cases is at most .
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is Arnar's chance of touring the factory. Print with exactly 10 digits after the decimal point, rounding the 11th digit half up.