Professional Documents
Culture Documents
2005/10/30
There are 9 problems, 21 pages, in this problem set. The team who solves the most number of problems wins the contest. If more than one team solve the same number of problems, then the team who takes less time to solve the problems wins. Each submitted program will be judged to be either correct or incorrect. A correct program must solve all the test cases of the problem correctly. The time to solve a problem is measured from the beginning of the contest to the time the submission of the program which solves the problem correctly, plus a penalty of 20 minutes for each incorrect submission for the problem. There are no penalties for the submitions of the problems which cannot be solved correctly at the end of the contest. Sample input data and the output for the sample input are provided in each problem. You may create these sample input data to test your program. However, test cases used by the Judges may not be the same as the sample input. It is not necessary to include comments in your programs. Any algorithm can be used to solve the problems. However, a program whose running time exceeds 30 seconds will be considered to be incorrect. Each input le may contain more than one test case. The description of the input format is based on records. A record usually contains a list of data. Unless stated otherwise, these data may span more than one line. The number of characters in a line is no more than 255. A special record, usually one or more 0s, indicates the end of an input data. Anything after this special record should be ignored. The name of the input le for problem i is pi.in. Error checking of the input data is not required. You may assume that the input data are always correct. The output le must be the standard output, unless it is specied in the problem.
Input Format
The input le contains several test cases. Each test case is described in 2 lines. The rst line is an integer n, which is the number of centers. The second line contains n integers. Each integer indicates the number of nearby towns connected to the corresponding center. For example, 4 3 2 2 4 means that there are 4 centers a0, b0, c0, and d0. The center a0 connects 3 nearby towns, the center b0 connects 2 nearby towns, etc. Assume that each center can connect at most 60 towns. The last test case is followed by a 0, which signals the end of input le.
Output Format
For each test case print out the labels of each town. The output should be ordered by labels, not by the names of the towns. Print 8 (town, label) pairs in a line, except the last line. Print 1 blank line in front of each test case. If there are no solutions, print no solutions.
Sample Input
4 3 2 2 4 5 0 0 0 0 0 0
Figure 1: An illustration of a none perfect dominating set and a perfect dominating set In this problem, the input graph is a tree T with n vertices {1, 2, . . . , n}, where 1 n 1000. Write a program to compute the perfect domination number of T .
Input Format
The input consists of a number of test cases. Each test case consists of one tree, which has the following format: The rst line contains one positive integer m = n 1, which is the number of edges of the tree. The next m lines contain m edges such that one line contains one edge. Each edge is represented by two positive integers; the rst integer represents one end-vertex of the edge and the second one represents the other end-vertex. Finally, a 0 at the last line indicates the end of the input le.
Output Format
The output contains one line for each test case. Each line contains an integer, which is the perfect domination number of the corresponding input tree.
Sample Input
5 1 2 3 4 4 1 1 0 3 3 4 5 6 2
Input Format
The input le consists of several test cases. Each test case begins with an integer N, 1 N 30, the number of buildings in Tuxville. Each of the next N lines contains 3 real numbers x, y, and h which gives the position and the height of one building. The last test case is followed by a line consisting of a single 0. Every real number t in the input le has at most 3 digits after the decimal point and 999.999 t 999.999. Note that there may be two or more buildings of equal or dierent heights occupying the same position, such as buildings 3 and 5 in the second test case. There may also be three or more buildings lying on the same straight line as exemplied by buildings 1, 2, and 4 in the second test case.
Output Format
Print the x-y coordinates of the desired position for each test case on one line. Round all numbers to 3 decimal places, printing the trailing 0s after the decimal place as necessary.
Sample Input
4 2.0 1.0 1.0 -2.0 -0.2 1.3 -2.0 1.0 5 1.0 8.0 8.0 -4.0 -4.0 1.0 4.5 2.0 -4.0 1.0 0 0.2 0.3 7.9 0.1 4.0 1.0 8.0 2.0 3.0
Input Format
The input le consists of several test cases. Each test case begins with a integer V , 3 V 100, the number of villages on the continent. Each of the next V lines contains 4 entries separated by spacesthe village name, the village population, and its position in x-y coordinates. The next line contains an integer E, 3 E 4950, the number of trails connecting villages. Each of the next E lines contains 2 village names separated by spaces. The last test case is followed by a line consisting of a single 0. Every real number t in the input le has at most 3 digits after the decimal point and 999.999 t 999.999. The names of the villages are in all capitals, and the length of a name is between 1 and 8, inclusive. The villages and the trails do not appear in any particular order in the input le. A trail between two villages, say ALF and BET, will appear only once, either as ALF BET or as BET ALF. Trails do not meet each other except at the villages. Every village is directly or indirectly connected to every other village. In computing the area of the forests, the trails are considered as straight line segments, and neither trails nor villages occupy signicant areas. Assume that the outer rim of the trail system is built along the coast line.
Output Format
For each test case, print on one line the smallest population density rounded to 3 decimal places, along with the desired forest denoted by its surrounding villages. For the population, print the trailing 0s after the decimal place as necessary. For the village names, print them in counter-clockwise order. Suppose the desired forest is surrounded by k villages. Of all k possible output sequences, print the one beginning with the alphabetically rst village. If there are more than one such sequences, print the one whose second city has the smallest alphabetical ordering. Thus we choose ALF BET ... over ALF EPS ... in the sample output.
3
500:ALF
400:BET
500:CALM
400:DEL
600:EPS
500:FIE
500:GO
400:HUA
-1
-2
500:ING
-3
-4
-3
-2
-1
In the sample input there are three forests. We nd their surrounding populations, areas, and densities to be the following, and therefore output information describing the second forest. Note that each of ALF and BET only contributes once to the collective population of the second forest. population area density 2000 2.000 1000.000 3400 5.500 618.182 1400 0.500 2800.000
Sample Input
9 ALF BET CALM DEL EPS FIE GO HUA ING 11 DEL ING ING ING ALF ALF ALF ALF BET BET FIE 0 500 400 500 400 600 500 500 400 500 CALM DEL HUA EPS DEL HUA EPS BET FIE GO GO 0.000 2.000 0.000 1.000 -3.000 0.000 -2.000 0.000 -1.000 0.000 0.000 0.000 1.000 0.000 2.000 0.000 0.000 -2.000
10
11
Input Format
The input le may contain several test cases. Each test case consists of a set of real-time disk tasks. The rst line of test case is a single integer n, representing the number of tasks. The second line of the test case has two numbers. The rst number is a real number, representing the disk speed b. The second number is an integer p, representing the current position of disk head. Starting from the third line, each line species a task. There are two integers in each line. The rst integer is the track location of the task. The second integer is the deadline of the task. All integers have the maximum value 1000000. The last test case is followed by a line containing 0. This signals the end of the input le.
Output Format
The output is a number t, the minimum execution time of all tasks. If no feasible schedules exist, output -1.
Sample Input
4 0.01 20 100 5 40 10 600 12 70 24 0
12
Input Format
The input le may contain more than one set of experimental records. The rst two line of each experimental record contains n and m respectively. Then follows by m lines, each line has two numbers i and j separated by a blank indicating the measurement result < i, j >. The last set of experimental records is followed by a line containing 0, indicating the end of test le.
Output Format
For each set of experimental records, output the number of suspicious measurements.
13
Sample Input
3 3 1 2 3 2 1 1 0
2 3 1
14
Figure 3: A solution to the Sudoku puzzle Some Sudoku puzzles may have unique solution. Dr. Susie thinks it is a good tool to enhance childrens patience. However, he wants to avoid dicult puzzles so that the children will be able to solve it in a reasonable amount of time. After some research, Dr. Susie noticed that the following two heuristics are easily understood by children: 1. Each numeral can appear in any row, column, and sub-grid only once. Therefore, if the union of the numeral appeared in the same row, column and sub-grid of some free cell contains 8 numerals, and leaves only one available numeral to be lled into that cell, then it should be lled with that numeral. For example, in Figure 4, the cell marked x can only be lled with 2 since all the other 8 numerals have appeared in the row, column and sub-grid of it. 15
2. Each sub-grid has to contain all the numerals. Therefore, if a numeral has not appeared in some sub-grid, say numeral 1, if there is only one free cell which can be lled by 1, due to the fact that all the other free cells in that sub-grid have 1 in the same row or column, then ll that cell with numeral 1. For example, in Figure 5 only the cell marked x can be lled with 1, all the other free cells are ruled out for the possibility due to 1s appeared in other sub-grid. 1 6 4 3 5 8 x 1 9 7
1 1
7 6 x 1
Figure 5: Heuristic Rule 2 He decided that if a puzzle can be solved by only applying the two heuristics above, then it is an easy puzzle, otherwise it is not an easy puzzle. You are to write a program to tell whether puzzles are easy or not easy.
Input Format
The rst line contains an integer n, n 15, indicating the number of puzzles. The following 9n rows contains n puzzles. Each puzzle consists of 9 rows. Each row contains 9 numerals0 indicates that the cell has to be lled, and other numerals indicate that the cell is given that numeral.
16
Output Format
The output are n bits. The i-th bit equals to 1 if the i-th puzzle is easy, and 0 if the puzzle is not easy.
Sample Input
2 0 0 3 1 5 4 9 6 8 7 0 3 1 5 4 9 6 8 8 0 0 9 2 7 3 5 1 8 0 0 9 2 7 3 5 1 0 0 0 8 3 6 4 2 7 0 0 0 8 3 6 4 2 7 3 0 5 4 9 2 8 0 6 3 0 5 4 9 2 8 0 6 0 8 0 5 6 3 2 0 9 0 8 0 5 6 3 2 0 9 0 0 0 7 1 8 5 4 3 0 0 0 7 1 8 5 4 3 0 0 0 3 8 1 7 9 2 0 0 0 3 8 1 7 9 2 0 0 8 2 4 9 6 3 5 0 0 8 2 4 9 6 3 5 9 3 2 6 7 5 1 8 4 9 3 2 6 7 5 1 8 4
Sample output: 01
17
2 1 5
6 3
wl (T ) = (1, 2, 1, 4, 1, 2)
Figure 6: The left-weight sequence of a tree T . The number of binary trees in Bn is given by the Catalan number Cn = 1 2n . n+1 n
For example, all the left-weight sequences of T B4 are listed in Table 1 in lexicographic order. The rank of a left-weight sequence is its ordinal number in the lexicographic order list of all left-weight sequences in Bn . For example, the rank of the tree T B4 with wl (T ) = (1, 1, 2, 4) is 7. Design a program for computing the rank of a specic binary tree T Bn .
Input Format
The input le consists of several test cases. Each test case starts with a positive integer n, 3 n 10. Then followed by a line which contains the left-weight sequence of a specic binary tree. The line containing a 0 indicates the end of test cases.
Output Format
For each test case, output the rank of the given left-weight sequence in one line.
18
Rank weight sequence 1 1111 2 1112 3 1113 4 1114 5 1121 6 1123 7 1124 8 1131 9 1134 10 1211 11 1212 12 1214 13 1231 14 1234 Table 1: Left-weight sequences of T B4
Sample Input
5 1 1 1 1 2 8 1 2 3 1 1 2 1 8 10 1 1 2 1 5 1 2 1 4 1 0
19
Input Format
The input le consists of a number of test cases. The rst line of each test case is a positive integer n, which is the number of locations. These n locations are denoted by positive integers 1, 2, , n. The next n lines are information about connecting streets between these locations. The i-th line of these n lines consists of an even number of positive integers and a 0 at the end. The rst integer is a location j which is an out-neighbor of location i, and the second integer is d(i, j). The third integer is another location j which is an out-neighbor of i, and the fourth integer is d(i, j ), and so on. In general, the (2k 1)th integer is a location t which is an out-neighbor of location i, and the 2kth integer is d(i, t). The next case starts immediately after these n lines. A line consisting of a single 0 indicates the end of the input le. Each test case has at most 99 locations. The length of each street is a positive integer less than 100.
Output Format
The output contains one line for each test case. If the required bus-route-plan exists, then the output is a positive number, which is the total length of an optimal bus-route-plan. Otherwise, the output is a letter N.
20
Sample Input
3 2 1 1 8 2 3 1 5 4 7 6 6 3 2 3 2 0 2 3 1 0 1 3 2 0 3 2 7 0 3 3 2 4 4 4 2 6 3 1 2 6 3 8 5 7 1 1 7 7 9 5 8 2 0 4 4 0 0 0 0 0 8 1 0 0
1 0 1 0 1 0
Sample Output
7 25 N
21