0% found this document useful (0 votes)
89 views

Problem Set: The 34 ACM International Collegiate Programming Contest Asia Regional Contest - Hefei

This document describes the problems and sample inputs/outputs for the 34th ACM International Collegiate Programming Contest Asia Regional Contest hosted by University of Science and Technology of China. It includes 10 programming problems related to topics like airport collision detection, determining Mersenne primes, bubble breaker game strategies, laser path calculation in cuboids, dominant pattern identification, and K-neighbor substring matching. The full problem set is 23 pages in length.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

Problem Set: The 34 ACM International Collegiate Programming Contest Asia Regional Contest - Hefei

This document describes the problems and sample inputs/outputs for the 34th ACM International Collegiate Programming Contest Asia Regional Contest hosted by University of Science and Technology of China. It includes 10 programming problems related to topics like airport collision detection, determining Mersenne primes, bubble breaker game strategies, laser path calculation in cuboids, dominant pattern identification, and K-neighbor substring matching. The full problem set is 23 pages in length.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei

The 34th ACM International Collegiate Programming


Contest Asia Regional Contest - Hefei

Problem Set

Hosted by University of Science and Technology of China


Oct. 11, 2009

This problem set contains 10 problems; 23 pages totally.

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

Problem B: Mersenne Prime


A Mersenne number is a positive integer that is one less than a power of two:
Mn=2n-1.
A Mersenne prime is a Mersenne number that is prime. As of June 2009, only 47
Mersenne primes are known; the largest known prime number (243,112,609 1) is a
Mersenne prime.
They are named after 17th century French scholar Marin Mersenne(1588 1648),
who compiled a list of Mersenne primes with exponents up to 257. His list was only
partially correct. Mersenne gave little indication how he came up with his list, and its
rigorous verification was completed more than two centuries later. Many greatest
mathematicians made contribution on Mersenne primes, including Euler.
Now you have more computing power than those great mathematicians. Given a
positive integer n (n < 258), you should tell whether the Mn is a prime number. The
input ends with a 0.

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

Problem C: Bubble Breaker


Bubble breaker is a popular game on mobile phone.
It is simple but interesting. The gameboard consists of a
screen of differently-colored bubbles arranged in a matrix.
There are five different colors: red, blue, green, yellow and
purple. The player then clicks on any two or more
connecting same-colored bubbles to eliminate them from
the matrix, earning an appropriate amount of points in the
process. The more bubbles eliminated one time, the higher
the points added to the player's score. More specifically,
the rules of the game are as follows:
1). Bubbles are 4-connected to their horizontal and
vertical neighbors. Two or more connecting bubbles with
the same color can be broken at once;
2). Once some bubbles are broken, other bubbles on
top of them fall downwards. Whenever the player clears an
entire bubble column, the columns on its left slide right and
fill the gap.
3). The scoring of each bubble-breaking operation can be expressed in the
formula "Y=X(X-1)". X represents the amount of bubbles broken together, Y is the
resulting score. For example an elimination of 16 bubbles will result in 240 points
(240=16(16-1)).
John likes the game very much. And he has worked out a simple strategy to win
high scores for most cases. In his strategy, John assigns different priorities to bubbles
with different colors. If there are more than one set of connected bubbles with
different colors that can be broken in the gameboard, John always breaks red bubbles
at first, and then green bubbles, then blue bubbles, then yellow bubbles, and finally
purple bubbles. If there are multiple choices with the same color, John can always
break the proper bubbles and achieve a final score as high as possible. Now the
problem is, given a new bubble breaker game, what final score can John win using his
strategy?

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

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 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

Problem D: Laser in Cuboids


As we know, a cuboid (rectangular solid) has three mutually perpendicular edges:
a, b, c. When a, b and c are all integer, the cuboid can be regarded as abc small
cubes gluing together; each of the small cube is 111.

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

Problem E: Dominating Patterns


The archaeologists are going to decipher a very mysterious language. Now,
they know many language patterns; each pattern can be treated as a string on English
letters (only lower case). As a sub string, these patterns may appear more than one
times in a large text string (also only lower case English letters).
What matters most is that which patterns are the dominating patterns. Dominating
pattern is the pattern whose appearing times is not less than other patterns.
It is your job to find the dominating pattern(s) and their appearing times.

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

Problem F: K-neighbor substrings


The Hamming distance between two strings of the same length is defined as the
number of positions at which the corresponding characters are different. For example,
the Hamming distance between "abbab" and "bbabb" is 3.
A string is called a K-neighbor of another string if and only if they are of the
same length and the Hamming distance between them is not larger than K. In this
problem, given an integer K and two strings A and B which only contain character 'a'
and 'b', you are to count how many different sub-strings of A are K-neighbors of B.

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

Problem G: New Game


Alice and Bob are fond of a new interesting game. In this game, they play by
turns in a Directed Acyclic Graph (DAG). Every node of the graph is assigned a
non-negative integer at the beginning. Each round a player must choose a node having
a positive integer and transfer 1 to one of its succeeding nodes, i.e. its integer
decreases by 1 and certain succeeding nodes integer increases by 1. Who cannot find
such a node to transfer will lose, i.e. the integer is 0 in every node having at least 1
succeeding node.
Before playing the game, they come to an agreement about the integer assignment.
Alice plays first. To be fair, Bob is responsible for assigning an integer to each node.
But there is a constraint: the sum of all integers must be a predetermined value that
they both agree.
Now, given the sum, Alice wonders how many distinct assignments which will
prevent her from winning. Two assignments are different if there is one node assigned
different integers in the two assignments.
Alice and Bob are so smart that they can always find the best strategy.

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

Problem H: Chinese Paper Cutting


Paper cutting is the art of cutting paper designs.
Chinese Paper Cutting or Jianzhi is the first type of papercutting design, since paper was
invented by Cai Lun in the Eastern Han Dynasty in China. The art form later spread to other
parts of the world with different regions adopting their own cultural styles. Because the cut
outs are also used to decorate doors and windows, they are sometimes referred to "chung
hu", meaning Window Flower.
--WikiPedia
Alice is a fan of interesting Chinese paper cutting (ICPC). When she first saw it in her
grandmothers house, she immediately fell in love with this art. And from then on, she began
to collect various paper cutting designs and tried to create her own works as well. At first, she
couldnt manipulate her scissors and often cut inappropriate parts. Sometimes, she even hurt
herself. She had many beautiful designs in her mind, but she was unable to realize them. She
was so disappointed for that. However, she didnt give up. She persisted in practicing,
learning from books and experts. At last, she found a key feature of paper cutting. That is
symmetry.
Symmetry is very important for paper cutting. It not only beautifies the whole work but also
makes the cutting process easy. Therefore, cutting each part of a work independently is not a
good choice. Instead, it will be better to fold and cut alternately.
Now Alice is experienced and works out a paper cutting process which is safe and easy. So
she invents a machine that can perform paper cutting following her instructions.
This machine has a wide foldable board and a coordinate system on the board. Before the
machine runs, she puts a piece of rectangular paper on the board. Two edges of the paper
accord with X-axis and y-axis respectively. X-axis is from left to right and y-axis is from top
down.
Then she starts up the machine and performs a paper cutting process by repeating two types
of instructions:
z

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

As showed in figure 1, Sa is folded onto Sb to make A and B coincide,


meanwhile, the paper is folded along the line l . Then, Sa is
put back to the original position. But the folded area of the
paper is left on Sb.
In some cases, the paper may be completely within Sa. If so,
the whole paper will be reversed and left on Sb. In contrast,
the paper will be unchanged if it is completely within Sb.
The folding is limited to be vertical or horizontal.

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

, it will penetrate all of

them. After that, it will continue to cut along the segment


and then

, etc.

can be outside the paper. The machine will

cut nothing if it finds the knife is outside the paper.


Sometimes it may happen to cut along the joining line of two
layers. The knife is so sharp that it will cut off them all the
same.

16 / 23

The 34th ACM International Collegiate Programming Contest Asia Regional Contest - Hefei

Figure 2

If the paper is divided to several pieces after cutting, the


machine will automatically get rid of all pieces but the one
with the largest area (after unfolding). If there is a tie, it
will keep the one containing the most top-left point in the
original paper, i.e. the most left point in the most top
horizontal line.
Finally, she unfolds the paper and sees a fantastic design.
For some complex designs, she is not sure whether her instructions will exactly make what
she wants. She doesnt want to waste paper. So she needs you to write a program that can
simulate her instructions and tell her the final design. Given her instructions, your job is to
print the final design.

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

Problem I: Post offices


There is a straight highway with N villages alongside it. The villages are
numbered from 1 to N in one direction of the highway.The government is planning to
build at most M post offices in some of the villages.
The amount of money to build a post office in the i-th village is Ci and the i-th
village can be served by any post office within Ri kilometers to the left or right of it.
If a village has no post office built and no post offices in other villages can serve it,
the government has to compensate the villagers Pi money. Here Ci, Ri and Pi are all
non-negative integers.
You are to help the government to find a strategy of minimum cost.

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

Problem J: Super squares


There is a small kingdom. The kingdom consists of N towns and each town has
some residents.
Some pairs of towns are connected by bidirectional highways such that there is
exactly one highway path between each pair of towns. The king wants to select M
towns to build super squares in them so that the residents in the kingdom can gather in
these super squares to celebrate new years together. For some security reason, the
selected M towns must satisfies the condition that starting from any selected town,
someone can reach any other selected town by highways without passing through any
town which is not selected.
Each highway has a length. People always travel to the nearest town with a super
square to celebrate new years.
The king wants to make the total distance people have to travel to celebrate every
new year as small as possible. You are to help the king. The total distance is the
summation of distance every resident travel.

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

You might also like