Problem Set: The 34 ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Problem Set: The 34 ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Problem Set
1 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Problem A: Airport
Martin is the conductor of an airport in Mars. As the Martian scientists invented a
new kind of aircraft, Martin is going to have a nightmare.
The new aircraft looks somewhat like a sphere with different radii according to
the model. With the powerful engine, the aircraft can accelerate itself to a certain
speed in no time, and travel in that speed and direction until stopped. Furthermore, its
amazing braking system is able to stop the aircraft immediately.
Unfortunately, due to the global financial crisis, the Martian cant afford the
navigation system of the aircraft. That leads to a serious problem: the aircrafts may hit
each other while travelling.
Martins airport is going to replace the old aircraft with the new ones. If any
collision happens, Martin will lose his job. Martin has got the speed and radius of
every aircraft, together with their travelling plans. He wants to know when the first
collision happens, so as to take some actions to avoid the accident. You are the most
brilliant programmer in Mars, please help Martin!
Input
The input consists of multiple test cases.
In each case, the first line consists of an integer n (0n1000), which is the
number of aircrafts. Each of the next n lines describes an aircraft. The description for
each aircraft consists of 9 integers separated by single space: xi yi zi xi yi zi ri ti vi.
(xi, yi, zi) and (xi, yi, zi) indicate the initial position and destination of the center of
ith aircraft. ri, ti and vi indicate the radius, starting time and speed of the aircraft. The
aircraft will stay where it was when stopped. It is guaranteed that no two aircrafts will
touch or overlap with the other initially, and absolute values of all integers will not
exceed 10000. Notice that two aircrafts touching each other is considered to be
collision.
The last line of input is -1, which denotes the end of input file.
Output
For each case, output when the first collision happens with the precision of 0.01
in a single line. If there will never be a collision, just output the word Never.
Sample Input
2
0 0 0 10 0 0 1 0 1
10 2 0 0 2 0 1 0 1
2 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
2
1 1 1 3 3 3 2 10 2
-1 -1 -1 -3 -3 -3 1 2 1
4
0 0 0 100 50 20 1 1 2
100 50 20 0 0 0 2 3 4
200 300 150 100 50 20 3 0 1
10 10 10 110 60 30 1 1 2
2
0 0 0 4 5 3 3 0 1
6 7 5 1 2 0 2 5 1
1
1 2 3 1 2 3 100 10 8
-1
Sample Output
5.00
Never
20.76
5.26
Never
3 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Input
Each line of the input is a test case, which contains a positive integer n, n < 258.
The last line of input is 0, which denotes the end of input.
Output
For each case, output the number of n. After that, output Prime if the corresponding
Mersenne number is prime number, otherwise output NotPrime..
Sample Input
2
66
67
127
0
4 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Sample Output
2:Prime
66:NotPrime
67:NotPrime
127:Prime
5 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Input
The input consists of multiple test cases.
Each test case starts with a line containing two integers N and M (1<=N<=16,
1<=M<=11), which are the number of rows and columns of the gameboard. Each of
the following N lines contains M integers, ranging from 0 to 4, representing the
bubbles in the gameboard with different colors (0 = red, 1 = green, 2 = blue, 3 =
yellow, 4 = purple).
6 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Output
For each test case, print a line containing the test case number (beginning from 1)
followed by an integer which is the final score that John will get.
Sample Input
43
012
123
340
100
44
0123
1230
2301
3012
00
Sample Output
Case 1: 10
Case 2: 0
7 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Now, as in the above figure, there is a laser beam from one vertex to its diagonal
opposite vertex. The width of the laser is negligible, but we care about how many
small cubes the laser passes through.
Given the integer length of the three edges of the cuboid, your job is to work out
how many small cubes the laser passes through (not just contact with its edges or
vertices).
Input
Each line of the input is a test case, which contains three integer a, b and c, 0< a,
b, c<106. The last line of input is 0 0 0.
Output
For each case, output the number of small cubes the laser passing through.
Sample Input
113
223
333
000
Sample Output
3
4
3
8 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Input
The entire input contains multi cases. The first line of each case is an integer,
which is the number of patterns N, 1<=N<=150. Each of the following N lines
contains one pattern, whose length is in range [1, 70]. The rest of the case is one line
contains a large string as the text to lookup, whose length is up to 106.
At the end of the input file, number 0 indicates the end of input file.
Output
For each of the input cases, output the appearing times of the dominating
pattern(s). If there are more than one dominating pattern, output them in separate lines;
and keep their input order to the output.
Sample Input
2
aba
bab
ababababac
6
beta
alpha
haha
delta
dede
tata
dedeltalphahahahototatalpha
0
9 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Sample Output
4
aba
2
alpha
haha
10 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Input
The input consists of multiple test cases. Each test case starts with a line
containing one integer K(0<=K<=100,000). The following two lines give two
non-empty strings consisting of 'a' and 'b', which are string A and string B,
respectively. The length of strings A and B will both lie between 1 and 100,000,
inclusive.The last test case is followed by a line containing one -1.
Output
For each test case, print a line containing the test case number( beginning with 1)
followed by the number of different sub-strings of string A which are K-neighbors of
string B.
Sample Input
0
aabbab
ab
1
aabbab
ab
2
aabba
ab
-1
Sample Output
Case 1: 1
11 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Case 2: 3
Case 3: 4
12 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Input
The first line is a number indicating the number of test cases.
The first line of each test case includes three number N, M and S (2<=N<=100,
1<=M<=10000, 1<= S <=10000) indicating the number of nodes, the number of
edges and the sum of all integers respectively. Nodes are numbered by 0N-1.
The following M lines each have two integers, u and v, indicating an edge from u
to v (0 <= u, v <N).You can assume there is no cycle in the graph.
Output
For each test case, output a single integer indicating how many distinct
assignments in which Alice can NOT win. Because it can be very large, you should
output the remainder divided by 1,000,000,007.
Sample Input
3
2 1 3
0 1
4 3 3
0 1
13 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
1 2
2 3
3 3 5
0 1
1 2
0 2
Sample Output
2
10
6
14 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
fold A B:
To execute this instruction, the part of the board containing
the point A will be folded onto the other part. So the point
A will coincide with B after folding. Then, the folded part will
come back to the original position.
15 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Figure 1
cut
The machine is equipped with a small sharp knife. First, it will
use the knife to cut the paper along the line segment
there are multiple layers under
. If
, etc.
16 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Figure 2
Input
The first number indicates the number of test cases. It will not exceed 50.
For each test case, the first line contains two integers L, W (0<L, W<=100) indicating the
length and width of the paper. The top left corner of the paper is at (0, 0).
The second line is a single number T indicating how many instructions she will execute. (0<=
T <= 100)
The following T lines each are an instruction:
Or
Here
are the two points which should be in the same place after folding.
You can assume that they are distinct and locate in the same vertical or horizontal line.
) indicates the knifes path. All the segments are veridical or
horizontal.
17 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Output
The output of each case should consist of W rows. Each row includes L characters. If
the area of [j-1,j]*[i-1,i] remains in the final design, you should print a @ for the j-th
character of the i-th row; Otherwise, print a .
Output an empty line at the end for each test case.
Sample Input
3
3 3
3
fold 0 3 0 0
fold 3 0 0 0
cut 3 0 1 1 1
4 3
3
fold 4 0 0 0
cut 2 2 0 2 3
cut 4 2 1 1 1
12 14
8
fold 12 0 0 0
fold 0 14 0 5
fold 0 9 0 4
fold 0 0 0 5
fold 0 3 0 4
fold 0 0 5 0
cut 3 0 6 4 6
cut 5 6 4 3 4
1 0
1 2 2 2
4 10
3 5 5 5 5 10
Sample Output
.@.
@@@
.@.
@@..
@...
@@..
18 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
..@......@..
@@@@@@@@@@@@
..@......@..
@@@@@@@@@@@@
..@......@..
@@@@@..@@@@@
@...@..@...@
@@@@@..@@@@@
..@......@..
@@@@@@@@@@@@
..@......@..
@@@@@..@@@@@
@...@..@...@
@@@@@..@@@@@
19 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Input
The input consists of multiple test cases. Each test case starts with a line containing
two integers N(2<=N<=20,000) and M (1<=M<=N, M<=100).
The following line contains N-1 positive integers, which are the distances of between
village 1 and villages 2 ,3,...,N in kilometers.
The distances will be not greater than 1,000,000,000 and strictly increasing.
The third line of each test case contains N integers C1, C2, ... , CN, each of which is
between 0 and 10,000, inclusive.
The fourth line of each test case contains N integers R1,...,RN, each of which is
between 0 and 1,000,000,000, inclusive.
The last line of each test case contains N integers P1, ... , PN, each of which is between
0 and 10,000, inclusive.
The last test case is followed by a line containing two zeros.
Output
For each test case, print a line containing the test case number ( beginning with 1)
followed by the minimum amount of money the government has to pay.
Sample Input
32
12
232
110
10 20 30
20 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
32
10 20
100 2 300
567
10 100 400
00
Sample Output
Case 1: 4
Case 2: 312
21 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
Input
The input consists of multiple test cases. Each test case starts with a line
containing two integers N(2<=N<=2,000) and M (1<=M<=N, M<=500).
The following line contains N positive integers, the i-th of which is the number of
resident in the i-th town and will not be greater than 1000.
Each of the next N-1 lines contains three integers a, b and c (1<=a<b<=n,
1<=c<=1,000), which means there is a bidirectional highway between the a-th town
and the b-th town and the length of the highway is c kilometers.
The last test case is followed by a line containing two zeros.
Output
For each test case, print a line containing the test case number( beginning with 1)
followed by the minimum total distance people has to travel.
Sample Input
31
123
122
133
32
22 / 23
The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei
100 10 100
121
231
00
Sample Output
Case 1: 13
Case 2: 100
23 / 23