Westminster College 2008 High School Programming Contest October 14, 2008 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 nal. No cheating will be tolerated. 2008 Westminster High School Programming Contest Problem A: 1 Car Seats Randy has a problem. He drives a minivan and has three kids who each want to sit in the front seat. After several months of having the kids calmly decide whose turn it is on their own (\You had yesterday, now it's my turn!", \No I didn't, you sat up front yesterday, you big jerk", \Hey, don't forget about me, I NEVER get the front seat", etc), Randy has come up with the following scheme to put an end to the bickering. The oldest will have the front seat on the rst day of the month, the second oldest on the second day and the youngest on the third day. Then the pattern repeats, so the oldest has the front seat on the rst, fourth, seventh, etc. days, the second oldest on the second, fth, eighth, etc. days and the youngest on the remaining days. It didn't take long (of course) for the two youngest to see that the oldest would almost always have more days each month than the others, but Randy basically said \Tough, that's the rules". The youngest has asked you to come up with a program to exactly determine this inequity, and since it's possible that there may be more kids in the family someday (possible, but unlikely given all the current bickering), he wants you to write a program that can handle any number of kids. Input There will be multiple input sets. Each input set will consist of a single line, containing three integers n m k, where n is the number of kids, m is the starting month and k is the number of months to consider. For this problem, January will be month 0, and December will be month 11. For example, if the input were 3 2 4, then you would be asked to determine the number of times that three kids would sit in the front seat over the months March, April, May and June. Recall that each month has the following number of days: Jan - 31, Feb - 28, Mar - 31, Apr - 30, May - 31, Jun - 30, Jul - 31, Aug - 31, Sep - 30, Oct - 31, Nov - 30, Dec - 31. The maximum values for n and k will be 10 and 50. Input will terminate with a line containing three 0's. Output For each input set, output the number of days that each kid gets to sit in the front seat over the specied time period. Output the values from the oldest to youngest kid, and separate each value with a blank. Sample Input 3 2 4 7 10 3 0 0 0 Sample Output 42 40 40 15 15 14 12 12 12 12 2008 Westminster High School Programming Contest Problem B: 2 Dive Right In The scoring in Olympic diving competitions is done as follows: After the dives, each of the seven judges gives the diver a scores between 0 and 10, in increments of 0.5. Then the two highest and two lowest values are discarded, the remaining scores are added together, and that sum is multiplied by a diculty factor for the dive. For example, if the degree of diculty for a dive is 3.2 and the seven scores were 8.5, 8.5, 9.0, 7.5, 9.0, 9.0, and 7.0, then the two highest scores (two of the 9.0's) and the two lowest scores (7.0 and 7.5) are dropped, leaving 8.5, 8.5 and 9.0. These are added together to get 26, and multiplied by 3.2 to get 83.2. Your job is to automate this process. Input There will be multiple input test cases. Each case will consist of one line containing 8 values: the degree of diculty and the seven judges scores. The last line will contain 8 zeroes and should not be processed. Output For each test case, output the nal score for the dive. Sample Input 3.2 8.5 8.5 9.0 7.5 9.0 9.0 7.0 2.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 0 0 0 0 0 0 0 0 Sample Output 83.2 56.25 3 2008 Westminster High School Programming Contest Problem C: Crash! Otto Rex works for the Department of Motor Vehicle Safety, and he has a really cool job: he get's to smash cars together! More to the point, he is attempting to assess the damage done to cars when they meet at various angles and speeds. He uses two cars in the setup shown below. Car 1 always moves north at a set speed. Car 2 starts at the same time from a dierent location and angle and also moves at a (typically dierent) set speed. The problem is that if car 2's speed is not selected correctly, then the two cars will likely miss each other, and what's the fun in that! Otto has come to you to help him ensure the maximum amount of wreckage. To simplify the problem, you can view each car as a single point (shown at the tip of each car below), and assume they always move at their set speeds from the start time onwards (i.e., there's no time spent increasing speed from zero to the set speed). Your job is to determine the exact speed so that the two points (i.e. cars) will collide with each other. @@ North @@u 2 6- East 6 u 1 Input The input le will consist of multiple test cases. The rst line of the le will be an integer n indicating the number of input cases. Each input case will consist of two lines. The rst line contains three integers x1 y1 s which give the information about the rst car: x1 and y1 are the coordinates of its starting location, and s is its speed in feet per second. The second line contains three integers x2 y2 theta specifying the location of the second car and the angle of its line of movement (where theta=0 is east, and theta=90 is north). The value of theta will never be 90 or 270 (can you gure out why?). Output For each input test case output the speed which the second car must travel at to hit the rst car. Each test case will be guaranteed to have a unique answer, and no solution will involve car 2 going in revers. Output the answer to the nearest hundredth. Sample Input 2 0 0 10 -5 0 45 2 6 25 3 7 180 0 Sample Output 14.14 25.00 2008 Westminster High School Programming Contest Problem D: 4 Image is Everything One common problem in image processing is determining if two separate images are actually showing the same item, but at slightly dierent angles. We will simplify this problem by considering simple black and white images, and determining if they are dierent only by rotations of 90, 180 or 270 degrees. For example, the two images on the left below are actually the same, except for a rotation of 90 degrees, while the two images on the right are dierent. Input The input le will consist of multiple test cases. Each instance will start with a positive integer n 10 indicating that you will be reading in two n n images. The next n lines specify the rst image, each line containing a string of n characters consisting of 0's (whites) and 1's (blacks). The next n lines after this will specify the second image in a similar fashion. The input le will terminate with a line containing a single zero. Output For each test case output either Yes or No depending on whether or not the second image is the same as the rst save for a rotation of 90, 180 or 270 degrees. Sample Input 4 0000 0111 0110 0101 0101 0110 0111 0000 4 1010 1000 0100 0000 1000 0000 0010 1100 0 Sample Output Yes No 2008 Westminster High School Programming Contest Problem E: 5 Gas Attack You'd have to be a hermit (or a teenager without a car) to not have noticed how often gas prices have been changing lately. While in reality prices go up (and sometimes down) by 5, 10 or 15 cents at a time, often it seems that prices go up by factors of 5, 10 or 15. And that leads up to our problem: given a starting price for a gallon of gas and a specication of how prices change, determine the ending price. Input The input le will consist of multiple test cases. Each test case starts a line of the form p n, where p is the starting price, and n is the number of changes to consider. The next n lines will be of the form op val, where op is either +, -, * or /, and val is a real number. When op is + you should add val to the gas price; when op is - you should subtract val from the gas price; when op is * you should multiply the gas price by val; and when op is / you should divide (no matter how unlikely) the gas price by val. No operation will ever result in fractions of a penny. A line containing two 0's will terminate input Output For each test case, output the nal gas price. Sample Input 3.50 4 + 0.10 - 0.05 * 1.2 / 2 0 0 Sample Output 2.13 2008 Westminster High School Programming Contest Problem F: 6 More or Les Les Finster is a young boy who loves playing with words. Often he likes to nd out how many times his rst name appears in lines of text. For example, in the sentence Lest we forget, the axles need to be blessed by Paul, especially after a long trip. the letters \les" appear four times: in \Lest", \axles", \blessed" and \Paul, especially" (note that in the last example Les ignores punctuation and spaces). Les is a nervous sort and often wonders if he's missed one or more \les"s. He's come to you for help. Input The input le will consist of one test case. The case starts with a single integer n specifying the number of sentences to consider. The next n lines contain the sentences, one per line. Output For each line in the test case, output the number of \les"s contained in them. Do not count any \les"s which span two lines. Sample Input 3 Lest we forget, the axles need to be blessed by Paul, especially after a long trip. That last sentence was very strange. This line contains no "les"s...oops, except for that one. Sample Output 4 0 1