SPRING 2015 PROBLEM PACKET ADVANCED TIER SPONSORED BY PRESENTED BY: RULES AND REGULATIONS • • • • • • • • • • • • • • All participants must be Penn State students and must provide an active PSU email address. Teams will be broken up by skill level-‐-‐intermediate and advanced. Students that have taken 300-‐level and up CMPSC classes will be put in the advanced tier. Those who have taken 200-‐level and below will be put in the intermediate tier. All non-‐CSE students will be placed in the intermediate tier. Teams may consist of 1-‐3 people of any skill level. A team's skill level will determined by the highest skill level of a member in the team. Intermediate teams have the option to compete in the advanced tier, but advanced teams may not compete down. Teams will have four hours to complete as many problems as possible. The competition will consist of 10 problems ranging in difficulty from easy to hard for both skill levels. Teams are limited to one computer that they must bring themselves. Teams are permitted to bring books and use Internet sources during the competition. Solutions to problems must be written in C, C++, or Java. Source code for solutions will be uploaded to the judges who will compile and test teams' solutions. Compiled solutions will be limited to an execution time that will vary per problem. If a solution takes too long to finish executing, it is incorrect. Only standard libraries may be used. The C99 and C++98 standards are used for C and C++ respectively with GCC. Java solutions are compiled with Java 7. All input must be through standard input, and all output must be through standard output. Otherwise, a solution is incorrect. HINTS • • • • • • All submissions are subject to a time limit; take too long, and your process is killed. If you use C or C++, you must use `int main()` rather than `void main()` and NEVER use `system("pause")`. If you need `stdlib.h` or `math.h`/`cmath` you MUST explicitly `#include` these even though Visual Studio does not enforce this. Do not prompt for input. Anything your program prints is considered output and will be judged. Read each problem carefully and pay attention to the given input bounds. The submission system needs the Java JDK installed on your computer to run. It's a big download, so do that now if you haven't already. # 1 | POKAIR PROBLEM In the card game of Pokair, players are dealt two cards at a time, with each duo* being treated as an inseparable entity. A player scores N points on a dealt duo if it, along with some subset of the duos the player has in their hands, completes a set of N pairs. When a player scores, the dealt duo is thrown out (so the player's hand remains unchanged). When a player is dealt a pair, they score 1 point and the pair is thrown out. If a player does not score when a duo is dealt, the duo is added to those in the player's hand. For example, let's say a player has a score of 0 and the duos {4, Queen}, {King, 3}, and {5, 10} in their hand. • • • • Let's say they're dealt the duo {4, Queen}. The player scores 2 points, since the dealt duo, along with the {4, Queen} duo already in the player's hand, completes a set of 2 pairs (of 4s and Queens). The newly dealt duo is thrown out, leaving us with an unchanged hand. Next, they are dealt the duo {3, 7}. As it does n't complete any sets of pairs, this duo is added to the player's hand. The hand now contains the duos {4, Queen}, {King, 3}, {5, 10}, and {3, 7}. Then, the player is then dealt the duo {King, 7}. The player scores 3 points, as the duos {King, 3} and {3, 7} from the player's hand, with the {King, 7} duo being dealt, complete a set of 3 pairs (of 3s, 7s, and Kings). The {King, 7} duo is thrown out. Thus, the player is left with a score of 5 and a hand containing the duos {4, Queen}, {King, 3}, {5, 10}, and {3, 7}. Your task is to design a program which will interpret a game of 1-‐ Player Pokair for a given list of dealt duos. *The strange terminology here is to avoid ambiguity. "Duo" refers to two cards of any denomination dealt together, while "pair" implies two cards that match in denomination. INPUT The first line of input is an integer H such that 0 < H < 107, where H is the number of duos to be dealt to the player. The subsequent H lines of input are given as two singular alpha-‐numeric characters, separated by a space, representing the two cards of each duo: 2s through 9s are given as their value, while a 10 is given as "T," a Jack as "J", a Queen as "Q", a King as "K," and an Ace as "A". Duos are dealt from an infinitely-‐sized deck where each card is equally likely to be chosen, and each dealing is independent. OUTPUT Output should be given as a single line containing two non-‐negative integers S and R, separated by a space with S preceding R, where S is the final score and R is the number of remaining duos after the dealings described by the input are completed. SAMPLES Input 5 2 2 2 5 5 Q 5 2 K 3 Output 3 2 # 2 | BIPPITY BOPPITY BOO PROBLEM You are the apprentice for an all-‐powerful sorcerer, Dictionario. Dictionario derives all of his magic spells and incantations as series formed from words, all from pre-‐defined magic dictionaries. The longer the series, the more powerful the spell becomes. To create a spell, Dictionario selects a dictionary from which to work. In this dictionary, he chooses one word x. To add another word to his spell, he must add, delete, or change a single letter of x to create a new word y which lexicographically succeeds x within the dictionary. To add another word to his spell, he applies the same transformation to y and continues within the dictionary he is given. As his apprentice, you are tasked with finding the longest spell possible (i.e. the longest possible series of words that fits the constraints above) for different dictionaries. INPUT The first line will have one integer, the number of dictionaries you have to analyze. Dictionaries will consist of words, one per line, in lexicographic order and be separated by an asterisks (*). You may assume that the words in the dictionaries will be in all lowercase. No word in the dictionary will exceed 16 characters and there are at most 5,000 words in any dictionary. OUTPUT For every test, output an integer that represents the number of words in the longest potential “spell” or word series, each on its own line. SAMPLES Input 2 cat hop pop pike top * bath bat like mike rat rit rite zit Output 3 5 # 3 | ALL ABOUT THAT BASE PROBLEM One of your favorite math professors is becoming increasingly interested in analyzing trends in how the base system used to express a number is related to its representation using human-‐ readable characters. She asks you for some help designing software that can be used to analyze some of these trends, and while you don't really understand the end goal of the project, you agree to give it your best shot. Your task is to create a program which interprets a number N, given as a proper fraction expressed in a given integer base, and returns the number of digits needed to exactly express N in radix-‐point notation in some other given base. INPUT The first line of input is an integer C such that 0 < C < 107, where C is the number of cases to be solved. The subsequent C lines describe each case with a trio of comma and space delimited numbers I, S, and T, where I is the number of interest, given as a proper fraction, S is the base system of I, and T is the target base system of interest. Both I and T are integers between 2 and 36, inclusive, where numbers in bases greater than 10 are represented with the standard Arabic digits 0 through 9 and some subset of the standard English alphabet (for example, base-‐16 [commonly known as hex] numbers are represented with the digits 0-‐9 and the letters A-‐E). Note that a whole number is, inherently, a proper fraction, despite not having an explicit fractional part. Also note that a number with only a fractional part can be represented without a whole number digit (e.g. 0.5 = .5 and 0 1/3 = 1/3). It will always be possible to express the converted numbers in a terminating radix notation (e.g. there will never be infinitely repeating digits in the portion to the right of the radix point). OUTPUT Output should be given as singular positive integers that describe the number of digits needed to exactly express I in the radix-‐point notation of base T (synonymous with decimal-‐point notation for base-‐10), with each case's output on its own line. Do not terminate the output with a blank line after the last case. SAMPLES Input 4 1 1/2, 10, 2 13 44/100, 5, 10 5, 8, 4 M 8/50, 25, 5 Output 2 3 2 5 # 4 | PILES OF PINECONES PROBLEM As fall rolls around in State College, the abundant coniferous trees begin to shed their cones. While this is an exciting natural sight, these cones rapidly add up, creating larger and larger piles of pinecones. Our goal is to determine how large the various pinecone piles will become. We will assume that each node of a binary tree will "drop" the corresponding number of pinecones to the ground as the number in that node. We will assume that these pinecones will drop directly to the ground, creating stacks. Additionally, we will assume that the left and right sub nodes of a node are exactly one unit to the left and one unit to the right, respectively, of the parent node. For example, take the following tree: The nodes containing 5 and 6 will have the same horizontal position, but different vertical positions. Hence, the pinecones from the two middle nodes will fall onto the same stack. Pinecones within the nodes with 7 and 3 will fall onto stacks one unit to the left and right of the center nodes, respectively. When the pinecones drop from these nodes, three piles are created: the leftmost one contains 7 pinecones (from the leftmost node), the next contains 11 (from the nodes containing 5 and 6), and the rightmost pile contains 3. INPUT The input will contain >= 1 test case, where each line of input describes a binary tree. A tree is specified by giving the value in the root node, followed by the description of the left subtree, and then the description of the right subtree. If a subtree is empty, the value -‐1 is supplied. Thus the tree shown above is specified as: 5 7 -‐1 6 -‐1 -‐1 3 -‐1 -‐1. Each actual tree node contains a positive, non-‐zero value. The last test case is followed by a single -‐1 (which would otherwise represent an empty tree). OUTPUT For each test case, please display the case number (starting at 1), followed by the sizes of each pinecones stack on the next line, starting with the left most stack, using a single space to separate each pinecone pile. This display of the pinecone stacks must begin in column 1 and will not exceed 80 columns. Following each case, please output a blank line. SAMPLES Input 5 7 -‐1 6 -‐1 -‐1 3 -‐1 -‐1 1 1 -‐1 -‐1 1 -‐1 -‐1 -‐1 Output Case 1: 7 11 3 Case 2: 1 1 1 # 5 | MARKUP, MARKDOWN, MARK ALL AROUND PROBLEM You’ve recently joined a company interested in creating a new markup language, QaML. If you don’t know, a markup language is “a system for marking or tagging a document that indicates its logical structure and gives instructions for its layout on the page,” according to Merriam-‐ Webster. QaML aims to be like HTML, XML, and descriptive markup languages of that nature. While the senior developers have been arguing about the specific nomenclature of the tagging systems, you’ve decided to create a framework of an error checker for future developers. You’ve only managed to get the following information about the syntax of QAML from the senior developers Like most markup languages, markup tags will be encompassed in angle brackets (< >) Every starting tag must have and an ending tag, both with identical tag names An ending tag will be indicated with a ‘/’ preceding the tag name Proper tag names will be between three (3) and twelve (12) inclusive alpha-‐numeric characters and will be entirely in uppercase Everything else is fair game…. until the developers finally settle on names…. eventually. INPUT The first line will have one number specifying the number of test cases that will follow. Each test case will also begin with a number, LC. LC indicates the number of lines of text that will follow for that case. You may assume for testing purposes that LC will never be greater than 30000. Every line of text will end with a newline, so there is no line limit. OUTPUT For every test case, first print out [TEST CASE #] where # is the number of the current test case. This should be followed by a newline. Secondly, if after examining the text, there are no errors in terms of syntax, print out No Errors followed by a newline. If something in the text violates the above conditions, print out the line number where the error occurred, followed by the error (this can be seen more discretely in the sample output below). Once your program finds an error, there is no need to complete the rest of that test case. There are four potential types of errors: Invalid Tag Name (Not Within Character Bounds) Invalid Tag Name (Invalid Character) No Matching End Tag for XXXX No Beginning Tag for XXXX (XXXX would be the tag name in question) These errors are placed in order of priority and only one errors needs to be printed out if a single event violates more than one error. SAMPLES Input 3 1 <GOOD>Hello</GOOD> 3 <START> <NOEND>Where do I go? </START> 2 <SOMANYCHARACTERSOHMYGOD> hello world </SOMANYCHARACTERSOHMYGOD> Output [TEST CASE 1] No Errors [TEST CASE 2] Line 2 – No Matching End Tag for NOEND [TEST CASE 3] Line 1 – Invalid Tag Name (Not Within Character Bounds) # 6 | PASS OR PLAY PROBLEM You are playing a card game with some of your friends where each player has three options per round that can result in a large number of possibilities for each round. Players sit in a circle and are each dealt one card per round. The goal of the game is to have the highest card at the end of a round and multiple decks may be used for a large number of players. During each round: Each player may play their card by discarding it from their hand into the center of the table, possibly giving them a new card next round or each player may pass his card to the player on his right or each player may pass the card to the player on his left. In addition to these basic rules there are also other stipulations for each round. Each player must do something with their card (they can't hold the card) and at least one player must play their card. If no one plays a card then the round must be replayed. Players may also not exchange cards Let's represent a player's discarding as "V", passing the card to the right as ">" or else "<" (to the left). When we have several players, we assign a symbol to each (V, < or >) and list the players in order, starting with the player who is dealing. For example, two players, A and B, the combination ">>" and "<<" are forbidden. And because a card may not be exchanged "><" and "<>" are forbidden. Your task is to write a program that given the number of players in the game, N, which determines the number of possible set-‐ups, S, that can be made given the rules of the game. Your program should be able to handle up to 10 players. You have a lot of friends. INPUT The input consists of a sequence of values, one per line, where each value represents the number of players. OUTPUT Your output should be a sequence of values, one per line, where each value represents the number of possible set-‐ups for the corresponding number of players read in the same input line. SAMPLES Input 2 3 Output 5 16 # 7 | A DOG WHISPERER'S PERSPECTIVE PROBLEM Some modern day dog whisperers believe that the pet dog goes through three distinct cycles throughout their life, which all start at birth. These cycles are the spiritual, physical and emotional cycles which are of lengths 23, 28 and 33 days, respectively. Additionally, they believe that each cycle has a peek point sometime within that cycle. For example, the peak of a dog's physical cycle may mean that dog will be able to catch a frisbee it could not catch on off peak days. As the three cycles have different period lengths, the peaks will generally not all coincide on one day. The goal of this problem is to determine when all three of a given dogs cycles peak on the same day. For each cycle, you will be given the number of days from the beginning of the current year that one of it's peaks occurs (not necessarily the first peak). As well, you will be given the number of days from the beginning of the current year. You must determine the number of days from the given date to the next triple peak (day where all three cycles are at their peaks). You will not count the given date, hence if the current date is 15, and the next triple peak occurs at day 19, the answer will be 4, not 5. If a triple peak occurs on the given date, you should give the number of days until the next triple peak. INPUT You will be given >= 1 cases. Each case spans one line, giving you four integers: s, p, e and d. The values of s, p and e will correspond to the number of days from the beginning of the current year to which the next spiritual, physical and emotional peak occurs, respectively. d represents the given date, and may be smaller than s, p and e. You must assume that s, p, e and d will all be non-‐negative and at most 365. You may also assume that a triple peak will occur within 21252 days of the given date. Input will be terminated when s = p = e = d = -‐1. OUTPUT For each given input, print the case number, next triple peak, and the number of days. So for example, the output should read: 1. 2. 3. next triple peak: 1822 days next triple peak: 77 days next triple peak: 199 days Always use the plural form days, even if the answer is 1. SAMPLES Input 0 0 0 100 4 5 6 7 -‐1 -‐1 -‐1 -‐1 Output 1, next triple peak: 21152 days 2, next triple peak: 16994 days # 8 | PETER THE PERNICIOUS PLUMBER PROBLEM Peter is an evil plumber. One time Peter was cheated out of some insurance money, so he likes to try to get back at the insurance companies by damaging the buildings he works on. To do this Peter wants each water system he designs to have as much water pressure as possible. Peter has two types of connectors: The S connections takes two water systems as inputs. The output of the S connection is a water system with a water pressure equal to the sum of water pressures in the input pipes. For further clarification: Let W1, W2 denote two arbitrary water systems. Let P1 and P2 denote the water pressures of water system W1 and W2 respectively. S(W1,W2) = W3, where W3 is a new water system with a water pressure, P3, such that P3 = P1+P2. The M connection takes two water systems as inputs. The output of the M connection is a water system with a water pressure equal to the maximum water pressure of the two inputs. For further clarification: Let W1, W2 denote two arbitrary water systems. Let P1 and P2 denote the water pressures of water system W1 and W2 respectively. M(W1,W2) = W3, where W3 is a new water system with a water pressure, P3, such that P3 = max(P1,P2). Restrictions: The String describing the water system will contain no more than 100 characters and will only consist of the characters ‘S’, ‘M’, and ‘P’. There does not exist a pipe in the water system with a resistance greater than 1000. INPUT You will first be given an integer that denotes the number of test cases. Each test case begins with a string denoting how the entire water system is connected. This string will contain P’s, S’s, and M’s. The P’s will represent pipes, the S’s will represent S connectors, and the M’s will represent M connectors. Next is a list of integers each on its own line. Each integer represents a pipe that is available for building the water system. That is, each integer in the array, i, represents a pipe, Pi, with a diameter of 1/i, which is proportional to the water pressure in Pi. So, for the sake of the problem you can assume water traveling through pipe Pi will always have a water pressure of i. OUTPUT You will output the maximum possible water pressure for the system in each test case on a new line. If the string denoting how the water system is connected is invalid then you must output Invalid String on a new line. (Hint: How many resistance values should there be for the entire system?) SAMPLES Input 3 SPP 3 4 MPPSPP 5 8 20 300 MSPPSPP 4 130 650 32 Output 7 Invalid String 780 # 9 | PSU IDS PROBLEM It is possible in the future that Penn State will expand to a global campus but will still issue ID's in the same manner as it does today. With the increased number of students and alumni it will be necessary to adopt a longer form of ID consisting of up to 12 characters using the 10 digits. The set of numbers is chosen somewhat haphazardly. It's easier to produce sets of ID's if they are rearrangements of a specific selection of digits. For example if a code contains 3 occurrences of '1', 2 occurrence of '2' and 1 occurrences of '3', then there are 60 allowable combinations of code. Some examples are 121123 121132 121213 It should be noted that these results are presented in numerical order. Among all the possible combinations, these codes appear consecutively in this order Write a program to assist in the generation of ID numbers. INPUT The input will consist of a series of lines where each line contains a code. Your program will accept a sequence of up to 12 digits, which may contain repeated digits, and print the next code in numerical order. If the code would be the last in the sequence the message "Last Code" should be given. OUTPUT The output will consist of a series of lines where each line contains the successor to the input codes. You only need to output 3 of the next combinations. Multiple cases can be provided. Each case output should be separated by a new line. SAMPLES Input 112 1221 99 Output 121 211 Last Code 2112 2121 2211 Last Code # 10 | REBUILD THE STARK MANSION PROBLEM Remember when you had a house, Mr. Stark? First Loki let the aliens into New York City and they trashed up your spectacular skyscraper and then the Mandarin blew up your multi-‐billion dollar mansion in Malibu. Which brings us to now. The entirety of the basement was destroyed in the attack which housed state of the art hardware cobbled together from numerous vendors of which many had their own specific standard and substandard. Ahem. Apple. At either rate we must reassemble what remains of the recovered parts. Keep in mind that some parts may not have an endpoint due to other missing parts from explosions and such. Some parts may fit into multiple endpoints and some endpoints may accommodate multiple devices. The Stark Industries Research and Development Department is at your disposal as always. Our technicians should be able to fashion adapters to fit devices to different endpoints. Being filthy rich has its benefits of course, any adapter we manage to create we can produce an infinite quantity of. INPUT The input will be multidimensional. The first line will hold the number of cases (c) and is followed by a blank line. The next c lines will list a positive integer between 1 and 100 showing the number of endpoints available (e). The next e lines will list the types of endpoints available. Each endpoint has a string of at most 24 characters. The next line contains an integer between 1 and 100 indicating the number of parts (p). The next p lines will list the name of the part followed by the name of the endpoint it needs. Again a part name will be at most 24 characters. There is a space between the part name and endpoint. The next line will hold an integer between 1 and 100 indicating the total types of adapters (a) available. The next a lines describes how the adapter works: the endpoint, a space, and the type of part. There is a blank line between cases. OUTPUT Each case should result in a single integer indicating the number of parts that have no endpoint on its own line. Print a blank line between cases. SAMPLES Input 1 4 A B C D 5 repulsor B light C display B odometer B silica Z 3 B Z Z A Z D Output 1
© Copyright 2024