【gcj】2012 round 2 待填坑

解答

=====


代码 

=====


题目

=====

Problem B. Aerobics

The aerobics class begins. The trainer says, "Please position yourselves on the training mat so that each one of you has enough space to move your arms around freely, and not hit anybody else." People start milling around on the mat, trying to position themselves properly. Minutes pass, and finally the trainer is so annoyed that he asks you to write a program that will position all the people correctly, hoping it will be quicker than letting them figure it out for themselves!

You are given the dimensions (width and length) of the mat on which the class takes place. For every student, there is a circular area she has to have for herself, with radius equal to the reach of her arms. These circles can not intersect, though they can touch; and the center of each circle (where the student stands) has to be on the mat. Note that the arms can reach outside the mat. You know that there's plenty of space on the mat — the area of the mat is at least five times larger than the total area of the circles required by all the people in the class. It will always be possible for all the people to position themselves as required.

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case consists of two lines. The first line contains three integers: NW and L, denoting the number of students, the width of the mat, and the length of the mat, respectively. The second line contains N integers ri, denoting the reach of the arms of the ith student.

Output

For each test case, output one line containing "Case #n: y", where n is the case number (starting from 1) and y is a string containing 2N numbers, each of which can be an integer or a real number: x1y1x2y2, etc., where the pair (xiyi) is the position where the ithstudent should stand (with 0 ≤ xi ≤ W and 0 ≤ yi ≤ L).

As there will likely be multiple ways to position the students on the mat, you may output any correct positioning; but remember that you may not submit an output file more than 200kB in size.

Limits

1 ≤ T ≤ 50.
1 ≤ W, L ≤ 109.
1 ≤ ri ≤ 105.
The area of the mat is at least 5 times larger than the total area of the circles: 
5*π*(r12 + ... + rN2) ≤ W*L.

Small dataset

1 ≤ N ≤ 10.

Large dataset

1 ≤ N ≤ 103.
The total number of circles in all test cases will be ≤ 6000.

Sample


Input 
 

Output 
 
2
2 6 6
1 1
3 320 2
4 3 2
Case #1: 0.0 0.0 6.0 6.0
Case #2: 0.0 0.0 7.0 0.0 12.0 0.0

Problem C. 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 B looks like it's the highest from peak A we mean that B is further down the road than A; all peaks between A and B are below the line connecting the peaks A and B; and all the peaks that are further than B 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.

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case consists of two lines. The first contains one number, N, the number of peaks in the range. You began your trip on peak 1 and went forward to peak N. The next line contains N-1 numbers xi. The i-th number denotes the index of the peak that appeared to be the highest from peak i (note that peak N is the last peak, so there are no other peaks to see from there).

Output

For each test case, output one line containing "Case #n: y1 y2 ... yN", where n is the case number (starting from 1) and yi is the height of the i-th peak. You can output any solution agreeing with the input data, except that all the heights you output have to be integers between 0 and 109, inclusive.

If no solution is possible, output "Case #n: Impossible" instead.

Limits

1 ≤ T ≤ 30.
i < xi ≤ N.

Small dataset

2 ≤ N ≤ 10.

Large dataset

2 ≤ N ≤ 2000.

Sample


Input 
 

Output 
 
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

Problem D. Descending in the Dark

You are on the face of Mount Everest. You need to find shelter before you freeze, and it's dark! What do you do?

The good news is you have already memorized the layout of the mountain. It is a grid with certain squares impassable and other squares containing caves where you can rest for the night. The bad news is you don't know where you are, and it's too steep to climb up. All you can do is move left, right, or down.

Here is an example layout, with '.' representing a passable square, '#' representing an impassable square, and numbers representing caves.

######
##...#
#..#.#
#...##
#0#..#
####1#
######

Since it is so dark, you will move around by following a plan, which is a series of instructions, each telling you to move one square left, right, or down. If an instruction would take you to a passable square or to a cave, you will follow it. If it would take you to an impassable square, you will have to ignore it. Either way, you will continue on to the next step, and so on, until you have gone through the whole plan.

To help with your descent, you want to find out two things for each cave C:

  • What squares is it possible to reach C from? We will label the set of these squares by SC, and the number of them by nC.
  • Is there a single plan that, if followed from any square in SC, will finish with you at cave C? If so, we say the cave is lucky.

Note that you might pass by several caves while following a plan. All that matters is what square you finish on after executing all the steps, not what caves you visit along the way.

For example, in the layout above, cave 0 is lucky. There are 9 squares that it can be reached from (including itself), and the plan "left-left-down-down-left-down" will finish with you at the cave from any of those squares.

Input

The first line of the input gives the number of test cases, TT test cases follow, beginning with a line containing integers R and C, representing the number of rows and columns in the mountain layout.

This is followed by R lines, each containing C characters, describing a mountain layout. As in the example above, a '#' character represents an impassable square, a '.' character represents a passable square, and the digits '0'-'9' represent caves (which are also passable squares).

Output

For each test case, first output one line containing "Case #x:", where x is the case number (starting from 1). For each cave C, starting with 0 and counting up from there, write a line "CnC LC". Here, C is the cave number, nC is the number of squares you can reach the cave from, and LC is either the string "Lucky" or the string "Unlucky", as defined above.

Limits

There will be between 1 and 10 caves inclusive.
If there are d caves, they will be labeled with the digits {0, 1, ..., d - 1}, and no two caves will have the same label.
All squares on the boundary of the mountain layout will be impassable.
1 ≤ T ≤ 20.

Small dataset

3 ≤ R, C ≤ 10.

Large dataset

3 ≤ R, C ≤ 60.

Sample


Input 
 

Output 
 
2
7 5
#####
##0##
##1.#
##2##
#3..#
#.#.#
#####
7 6
######
##...#
#..#.#
#...##
#0#..#
####1#
######
Case #1:
0: 1 Lucky
1: 3 Lucky
2: 4 Unlucky
3: 7 Lucky
Case #2:
0: 9 Lucky
1: 11 Unlucky
In the first case, here are some valid plans you could use for the lucky caves:
  • For cave 0, you can use the empty plan. If you can reach the cave at all, you are already in the right place!
  • For cave 1, you can use the plan right-down-left.
  • For cave 3, you can use the plan right-right-left-down-down-down-left.

你可能感兴趣的:(【gcj】2012 round 2 待填坑)