Drummer (Large)
Time limit5sMemory limit512 MB
You choose a start time and beat gap so the worst deviation of the recorded strikes from the ideal beats is as small as possible.
- Level
Medium7 of 10
- Topics
- Binary search, Geometry, Math
- Solved
- No attempts yet
Problem
A drummer keeps the rhythm for the band. If the rhythm wobbles, the whole performance falls apart.
You are the lead singer of a popular rock band, and you have a problem. Your drummer just quit to become a professional gamer, so you need a replacement right now. Candidates are plentiful. Your job is to find the one who keeps the steadiest rhythm.
You audition the candidates one at a time. During an audition, a candidate strikes a single drum with a stick several times. In a perfect rhythm the gap between consecutive strikes is always the same, so the strike times form the arithmetic progression .
No human plays a perfect rhythm. Each candidate's performance differs from some perfect rhythm by at most at every strike. More precisely, pick a real number and a real number , let the perfect rhythm be , and define the error against that rhythm as
Given the strike times of one candidate, find the smallest error over all choices of and .
Input
The first line contains the number of test cases . Each of the test cases describes one audition and takes two lines. The first line contains the number of strikes . The second line contains integers separated by spaces, the strike times in milliseconds. The times are given in increasing order.
Limits
- (two strikes can share the same time)
Output
For each test case, print one line in the form Case #x: E, where is the test case number starting from 1 and is the smallest error the candidate could have.
The smallest error is always a rational number. Print as the irreducible fraction p/q, where is a nonnegative integer, is an integer greater than 1, and the two are coprime. If the denominator is 1, print only the integer instead of a fraction. For example, print 3/4 for an error of , and 2 for an error of .