Sie sind auf Seite 1von 20

Problem A

Breaking Equations
(Time limit: 1 second)

In this problem you are given the answer set A = {a1, a2, a3,,an}, where ai {0, 1, 2, 3,},
and six linear equations as follows.
2 1 1
x x c
1 3 4
x x x
7 6 5
x x x
9 8 11
x x x
10 2 6
x x x
2 9 12
c x x
Observe that c1 and c2 are integer constants. Given c1 and c2, your job is to find an efficient
algorithm to solve these equations. That is, you have to find the correct values of all xi. You
can be sure that the correct value of each xi
A, and that these equations can be solved.
Input
The first line of the input file contains 3 integers separated by a blank representing n, c1, and
c2, respectively. The second line of the input file contains an integer representing a1. The
third line of the input file contains an integer representing a2 and so on. The n+1
th
line
contains an integer representing an. In the test case, you can be sure that 12 n 7,000 and
each ai can be represented by a 32-bit integer.
Output
The output file has 12 lines. Report on line 1 the value of
1
x that solves the corresponding
linear equations, the value of
2
x on line 2, the value of
3
x on line 3, and so on. The 12
th
line
reports the value of
12
x that solves the corresponding linear equations.










Example
Input
16 100 -30
100
70
30
10
80
42
53
95
17
35
52
12
5
77
89
1000
Output
70
30
10
80
95
42
53
17
35
12
52
5



Remark: Solutions are not necessarily unique. You can report any solution.











.
Problem B
Pilots and Co-Pilots Pairing
(Time limit: 1 second)
Consider the problem called PILOTS AND CO-PILOTS PAIRING below. Let P = {p1, p2,
p3,, pm} be a set of m integers representing m pilots. A flight requires two pilots to fly the
airplane. Some of these pilots are not compatible, meaning they do not work well together
and the airlines prohibit them from working in the same flight. A compatibility list is a
collection of all compatible pairs of pilots who can work well in the same flight.
PILOTS AND CO-PILOTS PAIRING PROBLEM
INSTANCE: A compatibility list U of k pairs {{pa1,pb1}, {pa2,pb2}, {pa3,pb3},,{pak, pbk}},
where pai, pbi P.
PROBLEM: Compute the largest set L of compatibility pairs of pilots from the compatibility
list U such that, for any two pairs {p1, c1} L and {p2, c2} L, {p1, c1} {p2, c2} = .
Input
Let 1 pi 20,000. The first line of the input file contains an integer representing m. The
second line contains an integer representing k. The third line of the input file contains two
integers separated by a blank. This line represents the first pair in U. The fourth line of the
input file contains two integers separated by a blank. This line represents the second pair in
U and so on. Line k+2 contains two integers separated by a blank. This line represents the k
th

pair in U. In all test cases, 1 k 3,160 and 1 m 80.
Output
The first line contains an integer representing |L|. The second line contains 2 integers
separated by a blank. This line represents the first pair of pilots and copilots in L. The third
line contains 2 integers separated by a blank. This line represents the second pair of pilots and
copilots in L and so on. Line |L|+1 contains 2 integers separated by a blank and represents the
last pair of pilots and copilots in L.








.
Example
Input
10
7
1 3
4 3
2 3
5 6
7 8
9 10
8 9
Output
4
1 3
5 6
7 8
9 10





Remark: Solutions are not necessarily unique. You can give any solution.

.
Problem C
Rock the Boats!
(Time limit: 1 second)

Assume that you are a boat dock manager who has an unlimited number of boats. Each boat
carries the same total weight. Given weights of passengers and the total weight that a boat
can carry, your job is to put these passengers into the boats so that no boat will get
overloaded. In the name of the companys profit, you also want the minimum number of
boats. You are asked to report the minimum number of boats needed to carry the given
passengers.
Input:
Input contains multiple test cases, separated by a line break. The end of the input is marked
by a line with five zeros (00000). Each test case has two parts; the total weight that a boat can
carry (w) in kilograms in the first line, and the list of passengers weights (p), separated by a
space, also in kilograms in the second line. w and p are integers and 100 <= w <= 10,000, 0 <
p < 200. The number of test cases is less than 100.
Output:
For each test case, the minimum number of boats should be reported in the output file. The
first line prints the minimum number of boats for test case 1, the second line the minimum
number of boats for test case 2, and so on. Five zeros (00000) should be printed to mark the
end of the output.
Sample Input
1200
89 98 45 23 120 99 56 76 89 74 83 58 76 93 85 78 23 79 93 95 65 78 65

200
56 89 45 23 120 99 56 76 93 85 78 23 79 93 95 65 78 65 89 74 83 58 76
00000
Sample Output
2
9
00000


.
Problem D
Connect the Dots
(Time limit: 1 minute)
In his famous speech at Stanford University, Steve Jobs said The first story is about
connecting the dots. Thats your job today. Lets present it as a board game. You will be
given tables with multiple pairs of dots. Each dot is named by a capitalized English alphabet.
An example of such table is shown below.
R G
Y B G

B
R Y

The rule of the game is that you have to connect the pairs of dots with the same alphabet such
that the part that connects them does not overlap with each other. An example of the solution
of the above table is shown below.
R G
Y B G

B
R Y

As you can imagine, there can be multiple solutions, each with a different path assignment.
Your job is to find whether, for each table, there is only one path assignment or there are
multiple path assignments. You can be certain that all test cases have at least one path
assignment.
Input:
There are multiple tables in the input. Each table is in a line. The tables have equal row and
column sizes. An empty table cell is presented by a sharp sign (#). The last line of the input
is ended with five zeros (00000). The dots are dictated by capitalized English alphabets (A-
Z), so there is a maximum of 26 pairs of dots. The table sizes range from 5x5 to 100x100.
Output:
For each table, if there is only one path assignment, Y should be printed. If multiple
assignments exist, N should be printed. The output is ended with five zeros (00000).


.
Sample input
###RG#YBG##########B##R#Y

Y############G##BGRYR###B

##O#######BPGW#######RY################BM##W########YG##P#####
O######MG##########
00000
Sample Output
Y
Y
N
00000




















.
Problem E
Contiguous Subsequence
(Time limit: 1 second)

A sequence is an ordered list of elements.
s = < e1 e2 e3 >
Each element contains a collection of items.
ei = {i1, i2, , ik}
A sequence s is a contiguous subsequence of
w = <e1 e2 ek>
if any of the following conditions hold:
1. s is obtained from w by deleting an item from either e1 or ek
2. s is obtained from w by deleting an item from any element ei that contains at least 2
items
3. s is a contiguous subsequence of s and s is a contiguous subsequence of w (recursive
definition)
For example, given s = <{1} {2}>, sequences <{1} {2, 3}>, <{1} {3, 2}>, <{1, 2} {2} {3}>,
and <{3, 4} {1, 2} {2, 3} {4}> are all contiguous subsequences of s. However, <{1} {3}
{2}> and <{2} {1} {3} {2}> are not contiguous subsequences of s.
Given a sequence s, and n sequences to be compared with s, determine such n sequences are
contiguous subsequences of s.
Input:
Sequence s and the number of sequences n to be compared with s are in the first line. Then,
the following n lines contain the n sequences. The elements in a sequence are separated by a
space. And the items in an element are from the set {0,1,2,3,4,5,6,7,8,9} and are separated by
a dash -. Such numbers in an element is always in the increasing order.
Output:
There are n lines of the output. Each line of the output contains YES or NO. If the i
th

sequence is a contiguous subsequence of s, then print YES in line i. Otherwise, print NO.



.
Sample Input Sample Output
1 2 2
1 2-3
1 3 2
YES
NO
1 2 3
2 1 3 2
1-2 2 3
3-4 1-2 2-3 4
NO
YES
YES












.
Problem F
Character Matching
(Time limit: 1 second)

String matching is very crucial in various applications. In this problem, it is simplified to only
character matching.

Given a query of characters, as well as a character database containing a few sets of
characters, you are asked to determine the ranking result based on the matching between the
query and the database.
The ranking conditions are based on two rules as follows: 1) for each set of characters in the
database, the more of the number of matched characters to the query characters means that
the higher rank such set can obtain. 2) for the two or more sets with the same number of
matched characters, the distance between the matched characters determines the rank, i.e. the
less distance means the higher rank. In case of the query-characters have more than two
characters, the average distance, computed from all the pairs of the characters in the query-
characters, has to be calculated and compared. In addition, if any two or more sets still have
the same rank based on the two conditions, the lexicographic order is used to break the tie.
For example, if a given query of characters is AD, and the database contains ABCD,
A, ACD, DCA. The ranking result is ACD, DCA, ABCD, and A. Since
ABCD, ACD, and DCA have both A and D, however, the distances between A
and D of the latter two sets are only one character, while the distance of ABCD is three.
Observe that ACD is ranked before DCA by the lexicographic order.
Another example is when the set of query-characters is ACD, and the database contains
ABCD, ABECD. The average distance of the first set of characters, ABCD, is
(1+2+0)/3 from the pairs of AC AD and CD, while the average distance of the second set of
characters, ABECD, is (2+3+0)/3. Thus, the first set has the higher rank.

Input:
There are several test cases. There is no duplicate character in both the query and the
database. The possible input characters are in the set {A, B, C, D,, X, Y, Z}. The line with
--- (three dashes) specifies the end of each test case. The first line of the input file is the query
of characters of the first test case. The following lines are the sets of characters in the
database of the first test case. The first test case ends with ---. Then the subsequent test cases
follow the same fashion.


.
Output:
Each line contains the rank of the corresponding input. For each rank, the line number in the
database is reported.
Sample Input Sample Output
AD
ABCD
A
ACD
DCA
---
ABCD
A
B
C
---
3 4 1 2
1 2 3
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Z
Y
X
---
ZA
ZA
AZ
---
3 2 1
2 1






Problem G
Finding Survivors
(Time limit: 1 second)

Natural disasters have always been a significant threat to humanity. Human have been
developing many technologies to protect themselves from the disastrous consequences which
are usually severe. One of the technologies for dealing with such crises is the use of
autonomous mobile robots for searching for survivors in some specific areas. You are given a
task to write a program to control the robot for searching for the survivors. Assume that there
are automatic sensors which can detect nearby survivors by temperatures and movement and
the robot is initially at the origin. The input from the sensors comes as 2D coordinate (x-y)
whenever some movements and temperatures are detected. You need to write a program to
list the order of coordinates for the robot to visit, calculate the maximum number of survivors
it can reach and total energy it consumes.
For simplicity of control, the robot has been deigned to carry out the task based on the
following rules:-
1. The robots sensors are activated every 1 second. Namely, new observations will
be obtained every 1 second. Each observation may contain 1-5 coordinates.
2. The robot starts at coordinate (0,0).
3. One coordinate has only one survivor and survivors cannot move.
4. Given the current position of the robot and the list of all not-yet-visited
coordinates observed by the sensors so far, the robot will always go to the nearest
coordinate. If there are two or more nearest coordinates, the robot follows the
policy of first-come-first-serve. That is, the robot will always go to the nearest
coordinate that comes first.
5. The unit of the distance is meter and the distance can be calculated as follows.
Let (x1, y1) and (x2, y2) be two coordinates. The distance between the two
coordinates is |x1-x2| + |y1-y2|, where |x| is the absolute value of x. Note that both x
and y are integer.
6. The robot needs to consume 10 units of energy for 1 meter of traveling.
7. All observed coordinates must be visited unless the energy is insufficient.

Input:
The very first line of the input is the number of cases the robot is going to carry out its
task (number of environments). This is followed by the input detail of each case. For each
case, the first line of the input is the energy limit of the robot. The second line of the input
indicates the total number of observations in that case, N (N < 1000). Then, each observation
is input one by one to the program. For each observation, the first line of input indicate the
number of detected coordinates, M (M <= 5). Then, M coordinates are input one by one as

integer number in the form of x y. Note that all numbers are integer. Each test case is ended
with character E.
Output:
The output of each test case is shown respectively. For each case, the first line shows
the total number of survivors the robot can reach and the second line shows the total units of
energy consumed by the robot.

Figure 1 illustrates how the robot moves to reach each survivor one by one.







Sample Input Sample Output
2
500
4
3
3 2
10 1
11 9
3
5 6
6 3
1 10
4
3 0
9 3
13 8
7 10
2
6 6
10 7
E
300
2
2
1 5
2 7
3
0 2
1 6
3 8
E
11
490
5
200
Note: The sample input and output of the first case are based on the typical illustration shown
in Figure 1.











Problem H
The End of the World
(Time limit: 1 second)
Assume that the world is coming to its end. Mr. A and his family are among the very few
people who stay alive. He is driving a car along the road in Bangkok center finding his way
to get out of the city as soon as possible. However, the fuel is limited and most of the gas
stations have just been wiped out by the earthquake. At this point, it becomes clear that the
problem is how to select the best way to drive. Given that now Mr. A reaches the big junction
with N ways to go. With the help of the GPS, which surprisingly can still function, the
information about each way is provided in the form of the number of milestones and the
amount of fuel to reach them. At this point Mr. A wants to go to any one of the N ways.
Additionally, he wants to reach the last milestone in that chosen way. However, this
information seems to be useless to Mr. A, now that he is in panic and temporarily loses an
ability of calculations. Your task is to write the program to calculate a way that Mr. A should
take with the minimum use of fuel. If there are two or more ways that consume the same
amount of fuel, the program will always select the first one in the input file.
Input:
The first line of the input is the number of test cases. This is followed by the input of
each case one by one. For each case, the first line indicates an amount of gasoline in your car,
K (K < 50). The second line shows the number of ways to go (N, N < 10). Then the
information about each way out of all N ways is input. The information about each way
contains M+1 lines where M (0 < M < 1000) is the number of milestones in that such way.
The first line indicates M, followed by an amount of fuel required to reach each milestone.
Note that the amount of fuels required to reach any milestone is an integer and calculated
from the current car position. Each test case is ended with character E.
Output:
The output of each test case is shown respectively. For each case, the first line shows
the index number of the way Mr. A should take and the second line shows a total amount of
fuel for driving in such way. The third line states the result if Mr. A will finally reaches the
destination. The Y means yes and N means no.







Sample Input 1 Sample Output 1
3
30
3
3
11
5
2
2
7
9
2
1
20
E
21
2
2
11
14
5
2
1
7
3
6
E
30
4
3
11
5
21
2
15
20
3
17
9
5
1
32
E
2
16
Y
2
9
Y
3
31
N


Problem I
Wat Phra Singh Pads
(Time limit: 1 second)
Wat Phra Singh is a Buddhist temple and a popular tourist destination in Chiang Mai. Each
room in the temple has a number of stacks of chair pads. This is for the comfort of its visitors
to sit on these soft pads. Each stack consists of three chair pads. You want to cover the floor
of the room with these pads.

There are four rules for moving these pads.
1. The bottom pad cannot be moved.
2. A pad can only be moved vertically or horizontally.
3. A pad cannot be moved through walls.
4. A pad must always be placed next to the adjacent edge of the other pads from the same
pile.

The above patterns are correct.

The above patterns are NOT correct.
Your task is to find if the provided chair pads are sufficient to cover a given floor.

Input:
The first line of the input contains an integer number of test cases, N < 20. Each test case
starts with two integers indicating the dimensions of the room, W and H (width and height of
the room). The next H lines contain information of each row of the area. A row contains W
characters. There are 3 different characters. # means the wall of the room. S means the
location of the stack of 3 chair pads and means an empty area.
Output:
For each test case, if the provided chair pads exactly fit the area, 0 should be printed out.
However, if the provided chair pads cannot cover the area, a negative sign should prepend the
number of missing chair pads such as -3. On the other hand, if the room requires a fewer
number of chair pads, a positive sign should be printed before the number of extra chair pads
such as +8.
Example:
Sample Input Sample Output
3
7 3
#######
SS #
#######
8 4
########
# S #S#
S # S #
########
6 5
######
###S #
### #
S S#
######
-2
+1
0

Remark: In all test cases you are guaranteed to have exactly one solution for each test case.


Problem J
Tetris
(Time limit: 1 second)

Tetris is one of the most popular games ever. The game is to manipulate a falling shape to
create a connected line at the bottom of the screen. The completed line at the bottom will
disappear. All the above blocks will fall down. One strategy is to find the best position for a
falling shape by placing the shape on the lowest available block from the bottom.
You are required to follow the above strategy. In case that there are more than one position
for the falling shape to be located, you need to select the leftmost position.
To manipulate the shape, you may rotate the shape 90 degree each time. That means for any
falling shape, there are four different positions for the shape to fall down.
Input:
The first line of the input contains an integer number of test cases, N < 20. Each test case
starts with two integers specifying dimensions of the falling shape, W and H (width and
height of the shape). The next H lines contain information of each row of the shape. Sharp
characters (#) represent the shape. The next two integers show the dimensions of the screen,
M and N (width and height of the screen, respectively). The next N lines display information
of each row. The dollar sign characters ($) represent the edges of the screen and the sharp
characters (#) represent the shapes that have already fallen down. This pattern repeats for
the other test cases.
Output:
The output must begin with the test case number and the final map of the screen on the next
line.









Example:
Sample Input Sample Output
2
2 4
#
#
#
##
17 5
$ $
$ ## # $
$### # ##$
$######## ## ###$
$$$$$$$$$$$$$$$$$
3 2
##
##
10 6
$ $
$ $
$ ##$
$## ####$
$########$
$$$$$$$$$$
1
$ $
$ ## # $
$### ##### ##$
$########### ###$
$$$$$$$$$$$$$$$$$
2
$ $
$ $
$ ## ##$
$########$
$########$
$$$$$$$$$$

Remark: In all test cases you are guaranteed to have exactly one solution for each test case.

Das könnte Ihnen auch gefallen