Westminster College 2010 High School Programming Contest October 18, 2010 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. 2010 Westminster High School Programming Contest Problem A: 1 Cases Wild Danny loves playing on his Nintendo DS, but he has trouble keeping all of his games organized. Typically when we wants to play a new game, he finds the case with the game cartridge we wants to play, removes the old cartridge from the DS, puts the new cartridge in, but then puts the old cartridge in the new cartridge’s case, insteading of hunting down the approrpiate case. Things can get pretty confusing after awhile, since soon no game cartridge is in its appropriate case. For example, suppose there are three games cartridges A, B and C and initially each is in its proper case. If Danny plays game A first and then game B, cartridge A ends up in case B. If he then plays game C, cartridge B ends up in case C. If he then wants to play game A, he hunts around for a while until he finds it in case B, then swaps that with cartridge C, so cartridge C ends up in case B. If he then plays..., well, you get the idea. Input The input file will consist of multiple test cases. The first line will contain an integer n ≤ 20 indicating the number of games Danny plays, following by the names of the games, each one a single word. The next line will contain a single positive integer m indicating the number of times Danny plays a game, followed by the names of the games in the order that they are played. These names may spill over into one or more additional lines. Each game name will be different from the one that immediately precedes it. A line consisting of a single 0 indicates end-of-input. Output For each test case output each game name (except the last one played) and the case that it is currently in. Use the format shown below where a single space is used to separate every word. Games should be output in the order that they appear on the first line of the test case. Output for each test case should start with the case number as shown below. Sample Input 3 5 4 3 0 A B C A B C A B Mario Kirby Sonic Zelda Kirby Mario Kirby Sample Output Case 1: A in case C C in case B Case 2: Mario in case Mario Sonic in case Sonic Zelda in case Zelda 2010 Westminster High School Programming Contest Problem B: 2 A Shot of Confidence Tessa is an 8th grader who plays a lot of basketball and she has decided to enter a local free throw shooting contest. Initially the organizers of the contest were going to have each player shoot 25 free throws and keep track of how many each made. After thinking about this for a while, they thought that that might put a lot of pressure on the kids, so instead they came up with the following plan: each player shoots 35 shots, and their score is the most number of baskets they make in any stretch of 25 consecutive shots. For example, if Tessa’s 35 shots are the following (where S is a successful free throw and M is a miss) SMSMSSSSSSMSSSSSSSSSSSSSSSSMSSMMSSS then her best stretch of 25 shots are the ones underlined above, where she makes 23 of 25 shots (there is another equally good stretch of 25 starting one after the underlined stretch above). The organizers have asked you to automate the process of determining contestants scores. They also want to have the flexibility of changing the total number of shots (35 in the example above) and the number of consecutive shots searched for (25 in the example above). Input The input file will consist of multiple test cases. Each test case will consists of two lines. The first line will contain 2 integers n m, where n is the total number of free throws attempted and m is the length of the consecutive shots searched for. The next line will contain n characters, each character either ‘S’ or ‘M’ indicating a successful free throw or a miss. A line containing 0 0 will terminate input. Output For each test case output the contestants best score for the given list of made and missed free throws. Sample Input 35 25 SMSMSSSSSSMSSSSSSSSSSSSSSSSMSSMMSSS 10 7 SSSSSSSMMM 0 0 Sample Output 23 7 2010 Westminster High School Programming Contest Problem C: 3 Rocky Sylvester Stallion is an old horse who likes nothing better than to wander around in the fields around his stable. Sylvester is a little single minded and will walk in a straight line unless there is a rock in this path. If that’s the case, he does one of three things: 1) if there is no rock to his right, he turns right and continues walking straight in that direction; 2) otherwise, if there is no rock to his left, he turns left and walks in that direction; 3) otherwise, he turns around and walks back the way he came. In a particularly rocky field, he may make several turns in his walk and exit the field in quite an unexpected location. For example, in the field shown below, if Sylvester enters the field at square (1,4), he will follow the path shown (a total of 12 squares), exiting at square (3,5). 5 4 3 2 1 R R R R R R R 1 2 3 4 5 6 Many of his other animal friends are concerned about Sylvester, and would like to know where he ends up on his walks (in particular, his good friend, the ram Beau). That’s where you come in - given a description of a field and the location of Sylvester’s entrance, you are to determine where he will exit the field and how long it will take him to get there. Input The input file will consist of multiple test cases. Each case starts with three positive integers n m r indicating the number of columns (n) and rows (m) in the field and the number of rocks (r), with n, m ≤ 20. Following the first line will be lines containing the locations of the r rocks. Each location will be of the form col row, indicating the column and row of the rock. There will be no more than 1 rock in any location. Following the rock locations will be the entrance location for Sylvester. Sylvester’s starting direction will always be perpendicular to the side of the field he enters from (this location will never be a corner square) and there will never be a rock in his entrance location square. A line with three zeros will terminate input. Output For each test case, output the case number followed by the last square Sylvester hits before he leaves the field (Sylvester will never get trapped in any field) and the number of squares that Sylvester visited during his walks, counting repeated squares. Use the format shown in the examples below. Sample Input 6 2 5 1 5 1 0 5 2 1 4 5 2 0 7 2 5 3 1 4 4 5 3 6 2 0 0 Sample Output Case 1: 3 5 12 Case 2: 5 2 5 2010 Westminster High School Programming Contest Problem D: 4 PL8S R US Most states use a combination of letters and digits for there license plates; we will call this combination the license plate pattern. The exact number of letters and digits depends on how many license plates the state needs, which in turn depends on the population of the state. If a license plate pattern contains n letters and m digits, you can show that the total number of possible license plates is 26n 10m (using one of a set of mathematical principles known as the Fundamental Laws of Counting). For example, Pennsylvania uses 3 letters and 4 digits in its license plate pattern, so there are a total of 263 104 = 175, 760, 000 possible license plates. In reality, most states don’t use all 26 letters on their license plates. For example, many times they won’t use the letters ‘I’ and ‘O’ since they look too much like digits. If a state only uses 24 of the 26 letters, then the formula for the number of license plates becomes 24n 10m ; if they only use 23 letters, the formula is 23n 10m , etc. For this problem, you will be given the number of license plates a state needs and the number of letters used in its plates, and you must find the number of letters and digits to use in the plate patten to get as close to the number of plates needed without going under. For example, suppose you need 90,000 license plates, and you can use 21 letters. You could just use plates containing 5 digits for a total of 105 = 100, 000 plates, but the best choice would be 3 letters and 1 digit for a total of 213 101 = 92, 610. Input There will be multiple test cases. Each test case will consist of a single line containing 2 positive integers p and l, where p is the number of license plates needed and l is the number of letters that can be used on the license plates (l will never equal 10). Input will terminate with a line containing 0 0. Output For each test case, output the license plate pattern in the form LLL...DDD..., where the number of Ls and Ds equals the number of letters and digits in the optimal pattern. Preface each output line with the test case number as shown in the sample input. Sample Input 90000 21 92611 21 0 0 Sample Output Case 1: LLLD Case 2: DDDDD 2010 Westminster High School Programming Contest Problem E: 5 Undercut The game of Undercut is played between two people who each have five cards numbered 1 through 5. At each turn of the game each player secretly selects one of their cards and then they simultaneously reveal them. Points are then awarded as follows: the player with the higher card gets the number of points on the card unless the other player’s card is one less; in that case, the player with the lower card gets the sum of the two cards played (this is called an undercut). If both players play the same card, then no points are awarded. For example, if Anna and Katie are playing Undercut, and Anna plays a 5 and Katie plays a 3 then Anna gets 5 points; however if Anna plays a 5 and Katie plays a 4 instead, Katie would get 5+4=9 points. Undercut is a great mental game, as each side is thinking “Okay, they think I’ll play a 5, so they’ll play a 4, so therefore I’ll play a 3 to undercut them. But they’ll realize I’ll think that, so they’ll play a 2, so instead I’ll just play a 5. But then they’ll think...” Unfortunately, we can’t model thinking like that in this contest, so instead we’ll just give you a list of what each player played and ask you to determine the final score. To make things more interesting, we’ll change the rules slightly: if you undercut a 2 with a 1, you’ll get 6 points instead of 3 (in the real game, this makes it more worthwhile to play a 1). Input The input file will consist of multiple test cases. Each test case will start with a line containing a single integer n indicating the number of rounds for that game. Following this (on one or more subsequent lines) will be n pairs of integers indicating the cards played in each round - the first two numbers will be the cards played by Anna and Katie, respectively, in the first round, the next two numbers will be their plays in the second round, and so on. A line containing a single 0 will terminate the input. Output For each test case, output Anna’s and Katie’s scores using the format shown below. Sample Input 3 5 3 5 4 2 5 10 3 5 1 2 3 2 1 2 1 5 3 2 1 3 4 2 3 3 1 3 0 Sample Output Game 1: Anna 5 Katie 14 Game 2: Anna 16 Katie 26 2010 Westminster High School Programming Contest Problem F: 6 Ahcircyp prtoobgl reamp You’ve just intercepted an encoded message from your archenemy. While he is quite proficient in deeds of nefarious intent, he’s sort of a loser when it comes to encryption schemes. All he does to encrypt a message is to divide the message in half and then interleave them together, taking the first characters from the first half and second half, then the second characters from the two halfs, and so on. For example, if his original message was Send more monkeys! he would first strip out all of the whitespace characters and then divide what was left into two halfs Sendmore monkeys! Finally he would interleave them to get his “encypted” message Smeonndkmeoyrse! While this encryption scheme is easy to crack, the process is also a bit laborious. It’s time to automate the decryption! Input The input file will consist of multiple test cases. The first line of the file will contain an integer n indicating the number of messages to decrypt. The next n lines will contain the messages, one per line. No message will be more than 80 characters long. Output For each test case output the decrypted message, using the format shown below. There should be no whitespace in the decrypted portion of the output. Sample Input 2 Smeonndkmeoyrse! BruetANpoeMso Sample Output Sendmoremonkeys! ButNoMoreApes