#P13326. [GCJ 2012 #2] Mountain View
[GCJ 2012 #2] Mountain View
题目描述
You are walking through the mountains. It turns out that in this mountain range there is a peak every kilometer, and there are no intermediate peaks. On every peak, you lie down for a rest, look forward, and perceive one of the peaks in front of you to be the highest one. The peak that looks like it's the highest might not really be the highest, for two reasons: there could be a higher peak that is obscured by another peak that's closer to you, and not as high; or you could be looking down, and a faraway peak could look higher than a nearby one.
To be precise, when we say that peak looks like it's the highest from peak we mean that is further down the road than ; all peaks between and are below the line connecting the peaks and ; and all the peaks that are further than are below or on this line.
You don't know how high each peak is, but you have a very good memory; you've been on all the peaks; and you remember which peak looks like it's the highest from each of them. You would like to invent a set of heights for the peaks that is consistent with that information. Note that you were lying down when looking, so we assume you always looked from the ground level on each peak.
In this example, the fourth peak looks like it's the highest from the first and third peaks. When you're lying on the second peak, you can't see the fourth peak; the third one obscures it, and looks like it's the highest.
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case consists of two lines. The first contains one number, , the number of peaks in the range. You began your trip on peak and went forward to peak . The next line contains numbers . The -th number denotes the index of the peak that appeared to be the highest from peak (note that peak is the last peak, so there are no other peaks to see from there).
输出格式
For each test case, output one line containing "Case #: ... ", where is the case number (starting from ) and is the height of the -th peak. You can output any solution agreeing with the input data, except that all the heights you output have to be integers between and , inclusive.
If no solution is possible, output "Case #: Impossible" instead.
4
6
2 3 4 5 6
4
4 4 4
4
3 4 4
4
4 3 4
Case #1: 10 10 10 10 10 2
Case #2: 10 20 40 80
Case #3: Impossible
Case #4: 5 3 6 8
提示
Limits
Test set 1 (13 Pts, Visible Verdict)
Test set 2 (14 Pts, Hidden Verdict)