Westminster College 2015 High School Programming Contest March 9, 2015

advertisement
Westminster College
2015 High School Programming Contest
March 9, 2015
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. Output from your solutions should follow the format used in the Sample Output section for each
problem. Unless stated otherwise, single blanks are used to seperate all output, and no blanks
should appear at the end of any line.
7. Judges’ decisions are final. No cheating will be tolerated.
2015 Westminster High School Programming Contest
Problem A:
1
All Aboard
Kay Bell runs a Trolley car company in a small ski resort. The trolley car travels back and forth between
two stops, carrying passengers from the ski lodge to the ski lifts. Since most passengers ski back to the
lodge, the trolley is really only used by people in one direction. One problem she faces is determining
how often to run her cars – if she runs them too often, many of the cars will contain only a few people
and will be greatly under utilized; if she runs them too seldom, the cars will be all filled, but many
people may have to wait for long periods before they can get on a car. She would like to run some
simulations using data she has gathered and has offered to give a season-long ski pass to anyone who
can write a program to perform the simulation1 .
The data Kay has is the arrival time of each passenger at the trolley station, rounded to the nearest
minute, listed in increasing order. The station opens at 9:00 AM and closes at 9:00 PM, so all times
will be between 9:00 and 21:00 (using a 24-hour clock). If multiple people arrive at the same time, their
arrival times are repeated on the list. The two variables that Kay can change in each simulation is
1. the time t between trolley departures, where the first departure is t minutes after 9:00 AM, the
second is t minutes later, etc. Trolleys may run past 21:00 if there are still passengers waiting at
the station.
2. the number of passengers p which each car can hold (Kay is willing to buy new, larger cars if
necessary).
For each simulation, Kay wants to know the smallest number of passengers on any non-empty trolley
car run (she’s not interested in cars with no passengers in them), and the average wait time for all the
passengers. Passengers queue up in the order that they arrive at the station, so passengers that arrive
earlier will always get on the trolley before passengers who arrive later. Passengers who arrive at the
same minute that the trolley departs can still hop on (as long as there are seats available in the car and
no one is in front of them in line, of course).
Input
The input file contains multiple test cases. The first line of each test case contains three positive integers
n t p, where n ≤ 1000 is the number of arriving passengers, and t and p are as described above, with
t ≤ 60 and p ≤ 20. Following this are n arrival times of the form h : m where 9 ≤ h ≤ 21 and
0 ≤ m ≤ 59 (when h = 21, m will always be 0). These times may be listed over multiple lines; times on
the same line will always have one space separating them. A line containing three zeros will terminate
input.
Output
For each test case output the case number followed by two values: the smallest number of passengers in
any non-empty car, and the average wait time for all the passengers, rounded to the nearest minute.
1
Good luck cashing in on this
2015 Westminster High School Programming Contest
Sample Input
5 60 10
9 : 10 10 : 8 12 : 38 15 : 00 19 : 41
6 60 4
9 : 10 9 : 20 9 : 30 9 : 40 9 : 50 10 : 00
4 60 2
10 : 00 10 : 00 10 : 00 10 : 29
0 0 0
Sample Output
Case 1: 1 29
Case 2: 2 45
Case 3: 2 23
2
2015 Westminster High School Programming Contest
Problem B:
3
Bottled-Up Feelings
Peter is expecting a large shipment of fuel oil, but he has a small problem (doesn’t everyone in these
programming problems!). The only containers he has are a set of large bottles (each with the same
volume) and a set of smaller bottles (also each with the same, but smaller volume). Given the volume
of the shipment of oil, he would like to store the oil in the bottles so that
1. all of the oil is stored,
2. each bottle is filled to the top, and
3. the minimum number of bottles is used.
While Peter thinks he has solved this problem for his given bottle sizes, he often spends hours wondering
what would happen if his bottles had different volumes (apparently Peter doesn’t lead the most exciting
life).
Input
The input file contains multiple test cases. Each case consists of a single line containing three positive
integers s v1 v2 , where s ≤ 1000000 is the volume of the shipment, and v1 , v2 ≤ 1000000 are the volumes
of the two types of bottles, with v1 > v2 . A line with three zeros will terminate input.
Output
For each test case, output the case number followed by the number of bottles of size v1 and the number
of bottles of size v2 which satisfy Peter’s two conditions. If the conditions cannot be met, output
Impossible.
Sample Input
1000 9 7
1000 900 7
1000 10 7
0 0 0
Sample Output
Case 1: 108 4
Case 2: Impossible
Case 3: 100 0
2015 Westminster High School Programming Contest
Problem C:
4
Can You Raed Tihs Plorbem?
Recently researchers have found that people are able to read scrambled text as long as the first and
last letters of each word remain unchanged. This phenomena – given the name typoglycemia – is not as
universal as was originally thought, but still has the ability to surprise people. For example, consider
the following paragraph:
Tihs paagrarph has the ltetres of ecah wrod searcblmd, ecxept for the fsirt and the lsat in
ecah wrod. But I’m gisesnug you can sitll raed it. Pettry naet!
OK, but what has this to do with a programming contest? Not much, really, except for the following:
given two paragraphs of text you must determine if one is the scrambled version of the other.
Input
The ipnut flie ctnoanis mptulile tset cseas. Each test case starts with a line containing a positive integer
n ≤ 100 indicating the number of words in each paragraph. After this are n words (across one or more
lines) making up the first paragraph, followed by n words making up the second paragraph. Words in
each paragraph consist solely of lower-case alphabetic characters with a single space separating them –
no punctuation or digits are included. A single zero will terminate input.
Output
For each test case, output the case number followed by either the word Yes if the second paragraph is a
scrambled version of the first, or No otherwise. A legal scrambling follows the rules stated above – only
the interior letters of the word are scrambled.
Sample Input
6
ironically scrambled eggs is just eggs
inilcrloay slrbmcead eggs is jsut eggs
1
hello
goodbye
0
Sample Output
Case 1: Yes
Case 2: No
2015 Westminster High School Programming Contest
Problem D:
5
Mastering Mastermind
Mastermind is a two-person code breaking game which works as follows. The first person (the code
maker) creates a sequence of n colored pegs (with duplicate colors allowed) and hides it from view. This
sequence of pegs is the code. The second person (the code breaker) has the job of trying to determine
the code maker’s code and she does so by making a series of guesses. Each guess also consists of n
colored pegs. After each guess, the code maker gives the code breaker feedback about how close she is.
This feedback consists of two number r and s, where
• r = the number of pegs that are identical in both color and position in the code and the guess,
and
• s = the number of remaining pegs that are identical in color but not in the same position.
For example, if the code is BACC (where we use different letters to represent colors) and the guess is
CABB, then r = 1 (the A in the second position of both the code and the guess) and s = 2 (a B and
C in the remaining three characters). Note that only one of the B’s in the guess will “match” with the
single B in the code: once pegs in the code and the guess have been “matched” with each other, they
can’t be matched with any other pegs. Your job in this problem is to determine r and s given a code
and a guess.
Input
The input file contains multiple test cases. Each test case is a single line containing an integer n ≤ 50
(the length of the code) followed by two strings of length n – the first of these is the code and the second
is the guess. Both code and guess are made up of upper-case alphabetic characters. A line containing
a single zero will terminate input.
Output
For each test case, output the case number followed by the values of r and s for that case.
Sample Input
4 BACC CABB
13 ABCDEFGHIJKLM NOPQRSTUVWXYZ
0
Sample Output
Case 1: 1 2
Case 2: 0 0
2015 Westminster High School Programming Contest
Problem E:
6
Shuffling Along
Most of you have played cards games (and if you haven’t, why not???) in which the deck of cards is
randomized by shuffling it one or more times. A perfect shuffle is a type of shuffle where the initial deck
is divided exactly in half, and the two halves are perfectly interleaved. For example, a deck consisting
of eight cards ABCDEFGH (where A is the top card of the deck) would be divided into two halves
ABCD and EFGH and then interleaved to get AEBFCGDH. Note that in this shuffle the original top
card (A) stays on top – this type of perfect shuffle is called an out-shuffle. An equally valid perfect
shuffle would start with the first card from the second half and result in EAFBGCHD – this is known
as an in-shuffle.
While normal shuffling does a good job at randomizing a deck, perfect shuffles only result in a small
number of possible orderings. For example, if we perform multiple out-shuffles on the deck above, we
obtain the following:
ABCDEFGH → AEBFCGDH → ACEGBDFH → ABCDEFGH → · · ·
So after 3 out-shuffles, the deck is returned to its original state. A similar thing happens if we perform
multiple in-shuffles on an 8-card deck, though in this case it would take 6 shuffles before we get back
to where we started. With a standard 52 card deck, only 8 out-shuffles are needed before the deck is
returned to its original order (talented magicians can make use of this result in many of their tricks).
These shuffles can also be used on decks with an odd number of cards, but we have to be a little careful:
for out-shuffles, the first half of the deck must have 1 more card than the second half; for in-shuffles,
it’s the exact opposite. For example, an out-shuffle on the deck ABCDE results in ADBEC, while an
in-shuffle results in CADBE.
For this problem you will be given the size of a deck and must determine how many in- or out-shuffles
it takes to return the deck to its original order.
Input
The input file contains multiple test cases. Each case consists of one line containing a positive integer
n ≤ 1000 (the size of the deck) followed by either the word in or out, indicating whether you should
perform in-shuffles or out-shuffles. A line containing a single zero will terminate input.
Output
For each test case, output the case number followed by the number of in- or out-shuffles required to
return the deck to its original order.
Sample Input
8 out
8 in
52 out
53 out
0
Sample Output
Case
Case
Case
Case
1:
2:
3:
4:
3
6
8
52
2015 Westminster High School Programming Contest
Problem F:
7
A Towering Problem
You’ve been put in charge of an art exhibit from the famous minimalist sculptor J (even his name is
minimalist!). J’s work involves the careful layout of vertically dispositioned orthogonal parallelpipeds
in a set of tapering obelisks – in other words, he puts smaller boxes on top of larger boxes. His most
recent triumph is called “2 by 3’s Decreasing”, in which he has various sets of 6 boxes arranged in two
stacks of three boxes each. One such set is shown below:
J has sent you the art exhibit and it is your job to set up each of the 6-box sets at various locations
throughout the museum. But when the sculptures arrived at the museum, uncultured barbarians (i.e.,
delivery men) simply dropped each set of 6 boxes on the floor, not realizing the aesthetic appeal of their
original layout. You need to reconstruct each set of 2 towers, but you have no idea which box goes
on top of the other! All you know is the following: for each set of 6, you have the heights of the two
towers, and you know that in any tower the largest height box is always on the bottom and the smallest
height box is on the top. Armed with this information, you hope to be able to figure out which boxes
go together before tomorrow night’s grand opening gala.
Input
The input file contains multiple test cases. Each test case consists of eight positive integers. The first
six represent the heights of the six boxes. These values will be given in no particular order and no two
will be the same. The last two values (which will never be the same) are the heights of the two towers.
All box heights will be ≤ 100. A line containing eight zeros will terminate input
Output
For each test case, output the case number followed by the heights of the three boxes in the first tower
(i.e., the tower specified by the first tower height in the input), then the heights of the three boxes in
the second tower. Each set of boxes should be output in order of decreasing height.
Sample Input
12 8 2 4 10 3 25 14
12 17 36 37 51 63 92 124
0 0 0 0 0 0 0 0
Sample Output
Case 1: 12 10 3 8 4 2
Case 2: 63 17 12 51 37 36
Download