#P13303. [GCJ 2013 Finals] Drummer

    ID: 15168 远端评测题 6000~12000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>计算几何2013Special Judge凸包旋转卡壳Google Code Jam

[GCJ 2013 Finals] Drummer

题目描述

The drummer has a very important role in any band -- keeping the rhythm. If the drummer's rhythm is uneven, it can ruin the entire performance.

You are the lead singer of a very popular rock band, and you have a bit of a problem. Your drummer has just quit the band to become a professional video gamer. You need to find a new drummer immediately. Fortunately, there is no shortage of candidates. Everyone wants a chance to join your band. Your task is to find the best drummer among the candidates, and you want the person who can keep the most consistent rhythm.

Your plan is as follows. You will ask each candidate to audition individually. During the audition, the candidate will play one drum by striking it with a drum stick several times. Ideally, the time difference between consecutive strikes should be exactly the same, producing a perfect rhythm. In a perfect rhythm, the drum strikes will have time stamps that follow an arithmetic progression like this: T0T_0, T0+KT_0 + K, T0+2×KT_0 + 2\times K, \dots, T0+(N1)×KT_0 + (N - 1)\times K.

In real life, of course, it is nearly impossible for a human to produce a perfect rhythm. Therefore, each candidate drummer will produce a rhythm that has an error EE, such that each TiT_i differs by at most EE from some perfect rhythm. Given a candidate's sequence of drum strikes, find the smallest possible EE among all perfect rhythms that the candidate might have been trying to play.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each one consists of two lines and represents the audition of one candidate. The first line contains a single integer -- NN. The next line contains NN integers separated by spaces -- the time stamps, in milliseconds, of the drum strikes played by the candidate. The time stamps are in increasing order.

输出格式

For each test case, output one line containing "Case #x: EE", where xx is the case number (starting from 1) and EE is the smallest among all possible numbers that describe the error of the candidate's drum strike sequence.

Your answer will be considered correct if it is within an absolute or relative error of 10610^{-6} of the correct answer.

3
2
10 70
4
0 10 19 30
6
2 5 10 15 20 24
Case #1: 0
Case #2: 0.5
Case #3: 0.75

提示

Limits

  • 1T100.1 \leq T \leq 100.

Small dataset (9 Pts, Test set 1 - Visible)

  • Time limit: 60 6 seconds.
  • 2N10.2 \leq N \leq 10.
  • 0Ti100.0 \leq T_i \leq 100.

Large dataset (20 Pts, Test set 2 - Hidden)

  • Time limit: 120 12 seconds.
  • For 90% of the test cases, 2N1000.2 \leq N \leq 1000.
  • For all test cases, 2N50000.2 \leq N \leq 50000.
  • 0Ti106.0 \leq T_i \leq 10^6.