Westminster College 2006 High School Programming Contest October 5, 2006

advertisement
Westminster College
2006 High School Programming Contest
October 5, 2006
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 les 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 to be considered nal. No cheating will be tolerated.
2006 Westminster High School Programming Contest
Problem A:
1
Anagrams
An anagram is a rearrangement of the letters in a word or phrase to obtain a second word or phrase. For
example, the word \dormitory" can be anagrammed to \dirty room" and the phrase \David Letterman"
can be anagrammed to \Nerd amid late TV" (for more interesting anagrams like these, check out
http://www.anagramsite.com { after the contest, of course). Notice that capitalization is not important,
just the rearrangement of letters. For this problem, you will be given two phrases (which may or may
not consist of a single word) and you must determine whether or not they are anagrams.
Input
There will be multiple input sets. The rst line of input will consist of a single integer n indicating the
number of input sets. Each input set will consist of a single line, containing the two phrases to compare,
each ending with a '/'. Each phrase will consist of just alphabetic characters and spaces.
Output
For each input set, output either the word \Yes" or \No" depending on whether or not the two phrases
are anagrams.
Sample Input
4
dormitory/dirty room/
David Letterman/Nerd amid late TV/
computer/cute EROM/
programming contest/raging comportments/
Sample Output
Yes
Yes
No
Yes
2
2006 Westminster High School Programming Contest
Problem B:
Deck Count
All Decked Out is a company that specializes in designing and building back yard decks. Ralph Cramden
is in charge of the initial design phase for new customers. Many times, customers will come in and ask
for a deck of a certain size, say 120 square feet. Ralph then gives them various options - they could
have a 10 by 12 foot deck, or a 24 by 5 foot deck, etc. Ralph often wonders how many dierent size
decks there are for a given square footage (even ridiculous sizes like a 1 120 foot deck). Since you
know Ralph and would like to curry favor with him (in order to get a discount on a deck of your own),
you have agreed to write a program which solves this problem.
Input
There will be multiple test cases. Each case of a single positive integer
where n 10; 000; 000. A value of n = 0 terminates input.
n
equal to the square footage,
Output
For each test case, output a line of the form "Case n: m", where n is the case number (starting at 1)
and m is the number of possible decks for the given square footage. For our purposes, a 10 12 deck
and a 12 10 deck are considered two dierent decks.
Sample Input
120
1201
0
Sample Output
Case 1: 16
Case 2: 2
2006 Westminster High School Programming Contest
Problem C:
3
The Highs and the Lows
Wilbur Post works for a company which provides educational services on-line. Students are able to take
tests anywhere in the country, and a computer in Wilbur's oce grades the tests and stores the grades
in a le. For assessment purposes, Wilbur needs to keep track of the two highest and two lowest grades
for each exam. Unfortunately, the person who originally programmed the computer to grade the exams
has been red, and Wilbur is more of a paper-pusher than a programmer. He has come to you for help.
He would like a program to read an exam le and output the grades he needs.
Input
There will be multiple test cases. Each test case will start with an integer n indicating the number of
exam grades. The remaining lines of the test case will contain the grades, 10 per line (except perhaps
the last line). The minimum value of n will be 4 and the maximum value of n will be 200, and each
grade is guaranteed to be unique. A value of n=0 will terminate input.
Output
For each test case, output a line of the form Exam n: h1 h2 l2 l1, where n is the case number (starting
at 1), h1 and h2 are the highest and second highest grades, respectively, and l1 and l2 are the lowest
and second lowest grades, respectively.
Sample Input
13
97 108 5 10 20 69 48 73 39 8
113 54 88
10
97 108 5 10 20 69 48 73 39 8
0
Sample Output
Exam 1: 113 108 8 5
Exam 2: 108 97 8 5
4
2006 Westminster High School Programming Contest
Problem D:
It's All Tanks to You
One typical task in military surveillance is analyzing satellite reconnaissance images. We can represent
these images as rectangular grids of pixels, where each pixel is either 0 (light), 1 (medium) or 2 (dark).
An example of such an image is shown below.
0
1
0
1
2
1
0
2
2
0
1
0
1
1
2
2
0
2
0
2
2
0
0
0
1
0
0
2
2
2
2
2
0
2
1
2
1
0
1
0
1
0
0
1
0
0
2
0
2
0
2
2
2
2
1
0
2
1
1
0
1
2
2
2
0
0
0
1
0
1
1
2
One of the more important items that can be searched for are tanks, which show up as a set of 1's and
2's in a distinctive pattern shown below on the left. This image can be rotated by 90, 180 or 270 degrees
in the satellite image, but is always the same size. The image to the right shows the location of 3 tanks
in the original image.
1
2 1 2
2 2 2
Tank
0
1
0
1
2
1
0
2
2
0
1
0
1
1
2
2
0
2
0
2
2
0
0
0
1
0
0
2
2
2
2
2
0
2
1
2
1
0
1
0
1
0
0
1
0
0
2
0
2
0
2
2
2
2
1
0
2
1
1
0
1
2
2
2
0
0
0
1
0
1
1
2
Since the military has quite a lot of money left over from the last round of congressional funding, it is
looking for someone they can vastly overpay to write a program to automatically search for tanks.
Input
There will be multiple test cases. Each case will start with two positive integers n m, indicating the
number of rows and columns in the satellite image. The next n rows will contain m characters each
from the set f0; 1; 2g. The maximum value for both n and m will be 50. The le will terminate with
the line 0 0.
Output
For each test case, rst output the number of tanks in the image. Then output the satellite image,
replacing all tank pixels with the letter 'T' and all other pixels with the character '.'. No two tanks
will overlap in any of the images.
(over)
2006 Westminster High School Programming Contest
Sample Input
6 12
001012102110
121202010021
022200102220
102022002121
210021122101
102022002002
1 1
2
0 0
Sample Output
3
..T.........
.TTT........
.TTT....TTT.
....TT..TTT.
....TTT..T..
....TT......
0
.
5
2006 Westminster High School Programming Contest
Problem E:
6
Speed Limit
Fred Murtz has a slight problem with his car: his speedometer is not working. In order to determine
how fast he is going, Fred has to estimate using his odometer and a digital clock on his dashboard
making sure he goes at as constant a speed as possible. Unfortunately, the digital clock only displays
hours and minutes (not seconds), so this can lead to a wide range of possible speeds. For example,
suppose Fred starts estimating his speed at 4:14, and after 4 miles the clock says 4:20. The problem is
that the true start time could have been anywhere from 4:14:00 to 4:14:59, and the end time could have
been 4:20:00 to 4:20:59, so the time it took to travel 4 miles could be anywhere from 5 minutes and 1
second to 6 minutes and 59 seconds. Using the shortest time gives a speed of 47.8 mph and the longest
time gives a speed of 34.4 mph.
In order to combat this, Fred usually makes two estimates to limit the range of possible speeds. Suppose
that his second reading starts at 4:25 and after 5 miles the clock reads 4:33. This will lead to a range
of speeds between 42.8 and 33.4. Combining this with the previous estimate, Fred now knows that his
speed is between 34.4 and 42.8, as the diagram below illustrates.
34.4
33.4
47.8
42.8
34.4
42.8
rst estimate
second estimate
combined estimate
Fred would just love to have a program to do this calculation automatically.
Input
There will be multiple input sets. Each test case will consist of two lines, each describing one estimate.
Each estimate will be of the form d t1 t2 , where d is the distance measured in miles, and t1 and t2 are
the start and stop times, respectively. Each time will be in the form hh:mm, where hh represents the
hours and mm represents the minutes. The maximum dierence between the times will always be less
than 12 hours, and the two times will never be the same. A line containing 0 0 0 will terminate input.
Output
For each test case, rst output the line Case n:, where n is the case number starting at 1. Then output
minimum and maximum speed of the combined estimate. Separate the two values with a single space,
and round all your values to the nearest tenth.
Sample Input
4 4:14 4:20
5 4:25 4:33
15 11:40 11:55
12 11:56 12:08
0 0 0
Sample Output
Case 1: 34.4 42.8
Case 2: 56.3 64.2
7
2006 Westminster High School Programming Contest
Problem F:
Take Me Out to the Ball Game
This has been an exciting year so far in the Penn-Ohio Little League Junior Pipsqueak (Midget class)
season. People across two states are clamoring for the latest standings and statistics of their favorite
teams. Tim O'Hara works for a local newspaper, and is in charge of printing the standings for the
league. For each team, he typically reports the number of wins they have, the number of losses, and
their record over the last 10 games (in the form of <wins>-<losses>). He orders the teams by the
number of wins they have. For example, one possible printout might look like the following:
TEAM
Zips
Kumquats
Coelacanths
Bozos
Zygotes
WINS
34
29
20
11
6
LOSSES
6
11
20
29
34
LAST 10
9-1
5-5
6-4
2-8
3-7
Tim works from a giant le that contains the results of every game played during the season, in chronological order. For short seasons, he can determine the statistics by hand, but for longer seasons, he
needs a little help.
Input
There will be multiple test cases. Each test case will start with a line of the form
n name1 name2 : : : namen
where n is the number of teams in the league and each namei is one of the team names (a value of
n = 0 will terminate input). The maximum value of n will be 5, the maximum length of any name will
be 12, and names will only consist of alphabetic characters. The next line will contain a single integer
m indicating the number of scores in the test case, and this will be followed by m lines of the form
namei s1 namej s2
indicating that team namei played team namej with the score s1 to s2 , where s1 may or may not be
greater than s2 (they will never be equal). Each team will be guaranteed to have played at least 10
games.
Output
For each test case, output the standings using a format similar to the one in the example. The only
stipulation is that you use no blank lines between teams, and that each column is left-justied. Teams
with the same number of wins should be printed in alphabetical order. Print a blank line after each
test case.
(over)
2006 Westminster High School Programming Contest
8
Sample Input
It's dicult to show sample data here. In the example below, assume that the rst score is listed 10
times and the second score is listed 7 times
2 Apricots Zucchinis
Apricots 8 Zucchinis
... (repeated 9 more
Apricots 4 Zucchinis
... (repeated 6 more
0
12
times)...
3
times)...
Sample Output
TEAMS
Zucchinis
Apricots
WINS LOSSES LAST 10
10 7
3-7
7
10
7-3
Download