Westminster College 2016 High School Programming Contest March 7, 2016

advertisement
Westminster College
2016 High School Programming Contest
March 7, 2016
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. Cheating is allowed and encouraged.
8. The previous statement is a lie!!! No cheating will be tolerated, and those caught cheating will be
disqualified from the competition.
9. All judges’ decisions are final.
2016 Westminster High School Programming Contest
Problem A:
1
Dinoscan
Sarah Tops is a paleontologist who specializes in the reconstruction of dinosaur skeletons. One problem
which she faces is determining whether two bones mesh together correctly. She has taken scans of all
the bones in her collection, so instead of physically trying to put bones together she plans to use the
scans to determine the appropriate connections between bones. Below on the left are scans of the ends
of two different bones:
1
1
1
1
1
1
0
1
0
1
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
Scan 1
0
1
0
1
0
1
1
1
1
1
1
1
1
1
1
Scan 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Combined
In each scan, a 1 indicates bone and a 0 indicates empty space. Two bones mesh together if the two
scans can be put together to form a solid rectangle of 1’s with no overlap. Scan 1 above can mesh with
Scan 2 (as shown above on the right), but Scan 1 cannot mesh with either scans 3 or 4 shown below:
0
0
0
1
0
0
1
0
1
0
0
1
0
1
0
Scan 3
1
1
1
1
1
0
1
0
1
0
0
1
1
1
0
1
1
1
1
1
Scan 4
Input
The input file contains multiple test cases. Each case starts with a line containing three positive integers
r c1 c2 , indicating the number of rows in both scans and the number of columns in the first and second
scans. Following this are r lines each containing c1 characters – this is the first scan. All characters in
the scan are either a ‘0’ or a ‘1’. Following this are r lines each with c2 characters specifying the second
scan. The maximum value for r, c1 and c2 is 20. In all test cases, the first column of scan 1 and the
last column of scan 2 contain all ‘1’s. A line containing three zeros terminates input.
Output
For each test case, output the case number followed by Yes if the two scans can be meshed together,
or No otherwise. When combining two scans, always try to connect the right hand side of the first scan
with the left hand side of the second scan.
2016 Westminster High School Programming Contest
Sample Input
Note: the first Sample Input uses scans 1 and 2 above, and the second uses scans 1 and 4.
5 5 3
11100
10000
11100
10000
11100
001
111
001
111
001
5 5 3
11100
10000
11100
10000
11100
001
111
011
111
001
0 0 0
Sample Output
Case 1: Yes
Case 2: No
2
2016 Westminster High School Programming Contest
Problem B:
3
Getting in Line with Art
Mike and Angelo are arguing about a recent sculpture exhibit they attended (I’m sure you get into
these types of arguments all the time). Both of them are aspiring artists, and as soon as they got
to the exhibit they each set up an easel and starting sketching the various sculptures they could see.
Their argument involves the number of sculptures in the exhibit. Mike insists there were only three
while Angelo swears there were five. After examining the layout of the sculpture from a map in the
exhibition brochure they realized the problem: from where Mike had set up his easel, one of the statues
(A) blocked his view of two others (C and E), as shown in the diagram below.
Both Mike and Angelo wonder how likely something like this can happen, so they’ve turned to you to
run some simulations. For simplicity you decide to represent each sculpture by a point on the x-y plane.
In this model, one sculpture can block the view of other sculptures only when they lie on the same line.
All you have to do now is write code which when given a set of points determines the maximum number
of those points that lie on a single line.
Well....what are you waiting for?
Input
The input file contains multiple test cases. Each test case starts with a line containing a single integer
n indicating the number of points, where n ≤ 100. After this are n pairs of integers xi yi indicating the
location of the points. These pairs of numbers are across one or more input lines. All coordinate values
lie in the range 0 . . . 1000 and no two points are the same. A line containing a single zero terminates
input
Output
For each test case, output the case number followed by the maximum number of points on any one line.
2016 Westminster High School Programming Contest
Sample Input
4
0 0 0 10 10 0 20 0
6
0 0 20 20
40 40 60 60 80 80
100 100
0
Sample Output
Case 1: 3
Case 2: 6
4
2016 Westminster High School Programming Contest
Problem C:
5
Hidden Words
Danny is a partial paranoid – he thinks only half the world is out to get him! He’s convinced that
this vast anti-Danny conspiracy is sending secret messages to each other via on-line media, so he scours
websites looking for clues to their evil plan. So for example, the other day he found the words “omega”
and “theta” in the following snippet from a restaurant review site:
... feeling at home, Gary ate the taco he bought ...
and later found the word “pascal” in another line in the same article:
... after you dip a scallop in the sauce ...
Notice how devilish Danny’s enemies are, hiding these words by splitting them over multiple words
while ignoring punctuation and capitalization. The fiends! Now, what “omega”, “theta”, and “pascal”
actually mean Danny has no idea, but he’s sure it can’t be good.
The problem for Danny is that there are just too many articles in too many websites for him to handle
on his own. He’s asked you to write a program that will scan a given sentence to see if a specific word
is hidden in it somewhere. And he knows they’re there!
Input
The input file contains multiple test cases. The first line contains a single integer n indicating the
number of test cases. Each test case consists of two lines. The first line contains a single non-empty
word in lowercase letters – this is the word to search for. The second line contains the sentence to search.
(NOTE: instructions on how to read in an entire line from a file are given at the end of this problem.)
This line will contain only lower and upper case letters, blanks and punctuation. The maximum length
of both the word and the line will be 80 characters each.
Output
For each test case, output the case number followed by the index of where the word starts in the
sentence, or the phrase not found if the word is not in the sentence. The index of the first character in
the sentence is 0, and you should count all characters in the sentence – including blanks and punctuation
– when calculating the index. If there is more than one occurrence, output the first location.
Sample Input
3
omega
feeling at home, Gary ate the taco he bought
pascal
... after you dip a scallop in the sauce ...
java
... after you dip a scallop in the sauce ...
Sample Output
Case 1: 12
Case 2: 16
Case 3: not found
2016 Westminster High School Programming Contest
6
Reading in Lines
C++: To read in an entire line into a string variable s use the global function getline() found in the
string library.
using namespace std;
...
string s;
...
getline(cin,s);
Java: To read in an entire line into a String variable s, use the nextLine method of a Scanner object.
import java.util.Scanner;
...
Scanner in = new Scanner(System.in);
String s;
...
s = in.nextLine();
WARNING: Suppose you want to read in an integer on one line and then read in the entire second line
of input. In this case you must perform one getline or in.nextLine call before reading in the second
line of input. This is because after reading in the integer using cin >> n or n = in.nextInt(), there is
still an empty string remaining on that line which will be read in by the next getline or in.nextLine.
So to read in an integer and then read in the entire next line, you must do something like the following:
C++
Java
int n;
string s;
...
cin >> n;
getline(cin, s);
getline(cin, s);
int n;
String s;
...
n = in.nextInt();
s = in.nextLine();
s = in.nextLine();
⇐
⇐
reads in blank line
reads in next line
⇒
⇒
2016 Westminster High School Programming Contest
Problem D:
7
Hoop Yourself
Kathy is a basketball player on a mission. Her school uses basketballs from three different manufacturers
and she’s convinced that one of these companies produces a better product than the other two. To test
this theory, she has amassed a wealth of data from various practices and hopes that she can use this
data to convince the athletic department to only use one type of ball. The data she has is the following:
For each jump shot taken at practice she knows the type of ball used and whether or not the shot was
successful. For example, if the three types of balls are identified with the letters A, B and C, then the
data (A,yes), (C,no), C(yes), B(no) indicates that one successful shot was take with ball type A, one
unsuccessful shot was take with ball type B and two shots were take with ball type C, one successful and
one not. Based on this (very small) sample Kathy would say that type A has a 100% rate of success,
type C has a 50% rate and type B has a 0% rate.
If that was all the data Kathy had, then she would say that type A is the ball to go with, but she has
much more data than this – data from 100’s of practices where in each practice 100’s of shots are taken.
She has come to you to help automate the ranking process.
Input
The input file contains multiple test cases. Each test case starts with a line containing a single integer
n ≤ 1000 indicating the number of data points in the sample. After this are n pairs ti si where each pair
represents one data point. In each pair ti is either the character ‘A’, ‘B’ or ‘C’, and si is either 1 (for
a successful shot) or 0 (for an unsuccessful shot). These pairs are given across one or more input lines
and there is at least one data point for each basketball type. A line containing a single zero terminates
input
Output
For each test case, output each of the data types and their success rates, one pair per line. Output the
pairs in sorted order, from most successful to least successful (there will never be a tie). Output the
success rate as a percentage, using the standard floating point output in your language of choice.
Sample Input
4
A 1 C 0 C 1 B 0
17
C 1 A 0 A 1 B 1 B 1 B 0 C 1 C 0 B 1 C 1 B 1 A 0 C 0 C 1 B 0 B 1 A 0
0
Sample Output
Using C++
Using Java
Case 1:
A 100
C 50
B 0
Case 2:
B 71.4286
C 66.6667
A 25
Case 1:
A 100
C 50
B 0
Case 2:
B 71.42857142857143
C 66.66666666666667
A 25.0
2016 Westminster High School Programming Contest
Problem E:
8
Prime Driving Conditions
Gabby has just bought a new car and needs license plates. In Pennsylvania license plates consists
of three uppercase letters followed by four digits. License plates are given out in lexicographic order,
meaning that plate AAA 0000 is first, followed by AAA 0001, AAA 0002, etc,. After AAA 9999 comes
plates AAB 0000, AAB 0001, etc., and after plate AZZ 9999 comes plate BAA 0000. The very last
plate is ZZZ 9999.
For most people, any old license plate will do, but not for Gabby. She insists that the 4 digit number
on the plate must be a prime number. Recall that a prime number is a number > 1 whose only factors
are 1 and the number itself. The first few prime numbers are
2, 3, 5, 7, 11, 13, 17, 19, 23, . . .
So if Gabby goes to the DMV to get a set of plates, and the next available plate is JPB 1285, she’ll wait
until plate JPB 1289 becomes available, since 1289 is the first prime greater than or equal to 1285. If
the plate had been JPB 9999, she would have waited for the plate JPC 0002.
Perhaps you see what we’re driving at here. Starting at a given license plate, find the first plate
lexicographically equal or greater that contains a prime number.
As a side note, this past January the largest prime number known to date was discovered. It is equal
to 274,207,281 − 1 and contains 22,338,618 digits. A little too large to fit on a license plate.
Input
The input file contains multiple test cases. Each test cases is on a single line and contains a three
character string followed by a 4 digit number. The three character string consists solely of uppercase
letters other than the string “ZZZ”. A line containing END 0000 terminates input.
Output
For each test case, output the case number followed by the license plate Gabby will accept.
Sample Input
JPB 1285
JPB 9999
END 0000
Sample Output
Case 1: JPB 1289
Case 2: JPC 0002
2016 Westminster High School Programming Contest
Problem F:
9
Time is of the Essence
Do you know how long one million seconds is? How about one billion seconds? Well, the answer to the
first one is
11 days, 13 hours, 46 minutes and 40 seconds
Accurate, but a little over-precise. A more reasonable answer might be “11 days, 14 hours” or just “12
days” (after rounding). As another example, if I asked how large three million inches were, you could
approximate it by saying either “47 miles” or “47 miles, 613 yards”. This sort of imprecision is what
we’re looking for in this problem!
Input
The input file contains multiple test cases. The first line of each test case is of the following form:
n name1 c1 name2 c2 . . . namen−1 cn−1 namen
Each namei is a unit of measurement and each ci is a conversion rate, telling you how many units of
type namei+1 are in a unit of type namei . For example, in the first sample input, this line tells you
that there are 24 hours in one day, 60 minutes in each hour and 60 seconds in each minute. The value n
indicates the total number of unit names and satisfies 2 ≤ n ≤ 10. All names are alphabetic strings with
no blanks and always specify the plural form of the unit (which you should use for output no matter
the value is associated with the unit). All conversion values are positive integers. Following this line is
a single positive integer m ≤ 2, 000, 000, 000 indicating an amount of the last unit (i.e., namen ). A line
containing a single zero terminates input.
Output
For each test case output the case number followed by two lines. The first line should give the closest
conversion of the input amount to units specified by name1 , rounded to the nearest integer. The second
line should do the same, but be a bit more precise using the two largest units – name1 and name2 .
When rounding, always round up when the fraction is ≥ 0.5. Note that there are no commas in the
output.
2016 Westminster High School Programming Contest
Sample Input
4 days 24 hours 60 minutes 60 seconds
1000000
5 years 365 days 24 hours 60 minutes 60 seconds
1000000000
2 feet 12 inches
11
0
Sample Output
Case 1:
12 days
11 days 14 hours
Case 2:
32 years
31 years 259 days
Case 3:
1 feet
0 feet 11 inches
10
Download