Westminster College 2013/14 High School Programming Contest February 6, 2014

advertisement
Westminster College
2013/14 High School Programming Contest
February 6, 2014
Rules:
1. There are six questions to be completed in two and 1/2 hours.
2. All questions require you to read the test data from standard input and write results to standard
output. You should not use files for input or output.
3. The allowed programming languages are C++ and Java.
4. All programs will be re-compiled prior to testing with the judges’ data.
5. Programming style is not considered in this contest. You are free to code in whatever style you
prefer. Documentation is not required.
6. Judges’ decisions are final. No cheating will be tolerated.
2013/14 Westminster High School Programming Contest
Problem A:
1
The Cost of Moving
You’ve been put in charge of reorganizomg the inventory at Alma1gamated, Inc. AI has factories at
various sites around the country, each site manufacturing different sets of products. Currently, each site
has all of their products stored in a row of warehouses, with each warehouse storing one type of product.
Your idea is to move these products around so that the warehouses store the items in alphabetical order.
For example, one site which manufactures xylophones, q-tips, zeppelins and jump ropes stores them in
four warehouses as shown at the top of the following figure:
BEFORE:
HH
H
HH
H
?
HH
H
?
HH
H
xylophones
q-tips
zeppelins
jump ropes
HH
H
HH
H
HH
H
HH
H
jump ropes
q-tips
xylophones
zeppelins
6
AFTER:
The arrows show how far each product would have to be moved in order for the warehouse to store
them in alphabetical order, which is shown at the bottom of the figure.
Management likes your idea but is concerned about the cost of moving all of the products. The farther
a product has to be moved, the more it costs, so before committing to any re-ordering they would
like to know the total length that all products have to be moved at any given site. In the site above,
xylophones would have to be moved a total length of 2 (measured in warehouses), zeppelins would have
to move 1 and jump ropes would have to move 3, for a total cost of 6. What you need is a program
that can determine this movement cost automatically.
Input
There will be multiple test cases. Each test case will start with a line containing a positive integer n
indicating the number of products at the site. Following that will be one or more lines containing the
n names of the products in their current order. Each name will be a single string, and a single space
will separate each consecutive pair of names on any line. The maximum value of n is 1000, and no two
product names will be the same. A single zero will terminate input.
Output
For each test case, output the site number followed by the total length of movements needed to reorganize the products. Follow the format shown in the Sample Output.
2013/14 Westminster High School Programming Contest
Sample Input
4
xylophones q-tips zeppelins jumpropes
12
partridges turtledoves frenchhens callingbirds goldenrings
geese swans milkers dancers leapers pipers drummers
0
Sample Output
Site 1: 6
Site 2: 48
2
2013/14 Westminster High School Programming Contest
Problem B:
3
A Jaw-dropping Problem to Vex the Quizzically Freakish
You all know what a pangram is, so I don’t have to tell you that it’s a phrase or sentence that uses
every letter of the alphabet at least once. You also know what the most famous pangram is, so I won’t
waste your time reminding you that it’s:
The quick brown fox jumps over a lazy dog
BUT, do you know what a double pangram is? Yes, yes, you’re right, it’s a phrase or sentence that uses
every letter at least twice. And a triple pangram is one that uses every letter at least three times. And
a ... well, we could go on, but the contest is only two and a half hours so we’ll stop here.
Input
There will be multiple test cases. The input file starts with an integer n indicating the number of
cases. Each test case will be a single line containing upper and lower case letters, as well as other
non-alphabetic characters such as digits, punctuation and spaces.
Output
For each test case, output the case number followed by one of the following phrases:
Not a pangram
Pangram!
Double pangram!!
Triple pangram!!!
Select the phrase that best describes the test case. For example, even though a triple pangram is also
a double (and single) pangram, the phrase Triple pangram!!! best describes it. There will be no test
cases which use every letter of the alphabet more than three times.
Sample Input
3
The quick brown fox jumps over a lazy dog.
The quick brown fox jumps over a laconic dog.
abcdefghijklmNOPQRSTUVWXYZ-zyxwvutsrqpon
2013/2014
Sample Output
Case 1: Pangram!
Case 2: Not a pangram
Case 3: Double pangram!!
MLKJIHGFEDCBA
2013/14 Westminster High School Programming Contest
Problem C:
4
Piece de Resistance
Phil love jigsaw puzzles, so much so that he will work on multiple ones at the same time. This drives
Phil’s younger sister Jane crazy, as all those puzzles take up tons of space in the house, and heaven
forbid anyone should disturb the master whilst he is working on a puzzle. So one day when Phil is out
of the house, Jane does something a little bit nasty. She removes one piece from each of the puzzles
and puts them all in a big pile in the middle of the kitchen. Needless to say, Phil was a tad upset
at this, but after an hour of chasing his sister through the house, cooler (and more exhausted) heads
prevailed and he came up with a plan. Phil has taken digital photos of each removed piece and of each
nearly-completed puzzle, and would like you to write a program to determine whether or not a given
piece fits into a given puzzle.
Input
The input file will consist of multiple test cases. Each case starts with a line containing 4 positive
integers r c n m, each ≤ 100. The first two integers gives the number of rows and columns in a puzzle
image, and the last two give the number of rows and columns in a piece image. Following this will be an
image of a puzzle. This will consist of r rows each containing c characters. Each character will either
be an ‘X’ (indicating a non-empty portion of the puzzle) or a ‘.’ (indicating a part of the hole left
after Jane removed a piece). After this will be an image of a jigsaw puzzle piece, consisting of n rows
each containing m characters. In this image, an ‘X’ indicates a portion of the piece, and a ‘.’ indicates
empty space around it. It is guaranteed that the first and last rows and the first and last columns of
the piece image will each contain at least one ‘X’. A line containing a single 0 will terminate input.
Output
For each test case, output the case number followed by either Yes or No depending on whether or not
the given piece will exactly fit the hole in the puzzle. By “exactly” is meant that every ‘.’ in the
puzzle image can be covered by an ‘X’ in the piece image, and that no ‘X’ in the piece image lies on
an ‘X’ in the puzzle image or outside the boundary of the puzzle. Each piece may be rotated 90, 180
or 270 degrees but may not be flipped over.
2013/14 Westminster High School Programming Contest
Sample Input
3 5 2 3
XXXXX
XX..X
X...X
.XX
XXX
3 5 3 2
XXXXX
XX..X
X...X
X.
XX
XX
3 5 2 3
XXXXX
XX..X
X...X
.XX
XX.
Sample Output
Case 1: Yes
Case 2: Yes
Case 3: No
5
2013/14 Westminster High School Programming Contest
Problem D:
6
Quadruple Your Pleasure
A Pythagorean triple is a set of three integers a, b and c which satisfy a2 + b2 = c2 . This concept can
be extended to the Pythagorean quadruple which is a set of four integers a, b, c and d which satisfy
a2 + b2 + c2 = d2 . Two example of Pythagorean quadruples are
12 + 22 + 22 = 32
and
1192 + 2382 + 6982 = 7472
Pythagorean triples are most often encountered when dealing with right triangles, where the values of a
and b are the two side lengths and c is the hypotenuse. There is an analogous geometric interpretation
of a Pythagorean quadruple: if we consider a rectangular prism with side lengths a, b and c, then d is
equal to the length of the long diagonal connecting opposite corners of the prism.
Relax - no geometry needed for this problem. All you need to do is the following: given a range [n, m],
count the number of Pythagorean quadruples with n ≤ a ≤ b ≤ c ≤ d ≤ m.
Input
The input file will consist of multiple test cases. Each test case will be a single line containing two
integers n m, where n < m. In each test case m ≤ 4000 and m−n ≤ 2000. A line containing 2 zeros will
terminate input
Output
For each test case, output the case number followed by the number of Pythagorean quadruples in the
given range.
Sample Input
1
1
1
0
3
10
2
0
Sample Output
Case 1: 1
Case 2: 6
Case 3: 0
2013/14 Westminster High School Programming Contest
Problem E:
7
Stock Answers
Megan Bucks is a multi-millionaire who keeps meticulous records of her financial dealings. She has
asked you to write a program to do a little bit of analysis of some stocks she owns. What she wants to
know is the following: over a specified number of days, how often did each stock have the highest value
among all the stocks? The data she has is the following: the initial value of each stock on the first day,
and for each subsequent day the change in value for each stock. For example, information for one stock
over 6 days might look like the following: 156 6 8 -4 3 -12. This would indicate that following stock
values: 156 162 170 166 169 157.
Input
The input file will consist of multiple test cases. The first line will contain two positive integers n d
indicating the number of stocks and the number of days. This will be followed by d lines each containing
n integers. The n values in the first of these lines are the values for each of the stocks on the first day, and
the values in the remaining d-1 lines are the changes in the values of each stock for each of the remaining
days. The maximum value for n is 50 and the maximum value for d is 10,000. A line containing two
zeros will terminate input.
Output
For each test case output the case number followed by n integers. The ith of these values should be
the number of times stock i had the highest value. Note that if two or more stocks share the highest
value for any day, they all count that day in their total.
Sample Input
2 5
100 110
2 -2
2 -2
2 -2
2 -2
3 4
30 30 30
1 1 1
-2 -2 -2
14 14 14
0 0
Sample Output
Case 1: 2 3
Case 2: 4 4 4
2013/14 Westminster High School Programming Contest
Problem F:
8
This Too Shall Pass
Tessa is a high school junior who plays on the soccer team. Her coaches are trying to put an emphasis
on passing, and they want to help players learn how to recognize when a teammate is open for a pass.
They’ve decided to model the field as a square grid like the one shown below. Each player (for both
the offense and the defense) takes up one grid square - the offensive players are indicated with numbers
and the defensive players with black circles. Each defensive player also has the ability to move to any
neighboring square in order to intercept a pass; the squares that each defender can guard are shown
with an X in them. Assume player 1 has the ball. Another player is considered open if the line drawn
from the center of that person’s square to the center of player 1’s square does not touch any of the
squares that can be reached by a defender. If the line touches a defenders area even at a single point,
then the pass could be intercepted. Offensive players never block a pass to other offensive players.
2
1 @ @ @
@ @ @
@
@ @~@
@
@ @ @
@
@ @
@ @ @ @
@ @
@ @ @ @
@~
@
@
@ @
@
@ @
@
@ @
@
@
3
4
In the above example, Player 1 can pass the ball to Player 2, but not to Players 3 and 4.
Having set up this great model, the coaches suddenly realize that they don’t have any ability to write
code to determine who is open and who is isn’t. One of the players has given them your name as a
computer whiz, so it’s time to get your game face on, put it all on the line, give 110% and code one for
the Gipper.
Input
The input file will consist of multiple test cases. Each case starts with four positive integers r c o d
indicating the number of rows (r) and columns (c) in the grid and the number of offensive and defensive
players (o and d, respectively). Both r and c will be ≤ 50. Following this will be o lines containing two
integers giving the row and column location of an offensive player (row and column numbering start
at 0). Following this will be d analogous lines for the defenders. The offensive players are numbered
1, 2, 3, . . . in the order that they appear in the input, and offensive player 1 is the one with the ball. No
two players will ever be in the same grid square. A line with four zeros will terminate input.
Output
For each test case, output the case number followed by a list of all the players that Player 1 can pass
the ball to. Output the numbers in increasing order, separated by a single space. Label each test case
as shown below.
2013/14 Westminster High School Programming Contest
Sample Input
7
5
6
0
0
2
4
2
0
0
1
1
0
0
0
0
7 4 2
1
5
1
6
0
5
5 2 1
0
4
2
4 4 0
0
1
2
3
Sample Output
Case 1: 2
Case 2:
Case 3: 2 3 4
9
Download