Problem A by wuzhenguang

VIEWS: 14 PAGES: 17

									         1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                        Cover Letter
         November 14, 1998

Dear competitors,

Welcome to the 1998 ACM Mid-Atlantic Regional Programming Contest. Attached is the packet of
questions to be solved. Each packet contains 8 questions, if one of your packets does not, please submit a
clarification immediately.

Each question will have an associated balloon color associated with it. As teams correctly solve questions,
balloons will be awarded the team. No balloons will be delivered during the last 30 minutes of the contest.
During this time period, no score updates will be published. Only the head judge will have the scores
during that period. The correlation between balloons and questions is as follows:

Question 1                                               Pink
Question 2                                               Red
Question 3                                               Green
Question 4                                               Yellow
Question 5                                               Black
Question 6                                               Blue
Question 7                                               Purple
Question 8                                               White

If something in the questions is not clear, please read the questions again. If the necessary information is
still not included, you may submit a clarification. If the judges feel the information is contained within the
question, a response will simply read “See the question”. If a meaningful question is submitted, all teams
will be sent the response.

All questions in the contest will read from Standard Input. All questions should write to Standard
Output.

All submissions for a given question will be graded in the order they are received. This is a time
consuming process. Please be patient. Do not resubmit the same solution multiple times, as that will only
count as multiple incorrect submissions and slow the system down. The following are the possible
responses to a submission:

Answer                               Meaning
Correct                              Congratulations – you should be getting a balloon.
Incorrect Format                     Something was wrong with the format of your output.
Incorrect Output                     Something was wrong with or missing from your output values
Run Time Error                       Your program crashed on my input.
Compile time error                   Your program would not compile.
Time Exceeded                        Required more than 2 minutes to execute.

Only one response per submission will occur. It is possible that if your format and output are both
incorrect for you to receive either incorrect format or incorrect output as a response.

After the contest, I will answer questions through email. My address is: hjudge@cslab.vt.edu
I reserve the right to refuse to answer any question. I do not intend to release either my solutions for the
questions, or the test data used in judging today.

Good luck in the contest. I have enjoyed preparing these questions. My hope is that you enjoy solving
them as much.

Rob Chambers
Head Judge, 1998 Mid Atlantic Regional
Here are the questions. A little additional information:

1.   Each packet contains 8 questions for the contest itself (question 1-8) and a cover letter. These should
     be copied and given to the teams at the start of the contest. 3 copies should be given to each team.
     Additional copies should be made for the other people who come to you’re site (judges, alternates,
     etc).
2.   Each packet also contains a sample problem. (Question 0). This is to be given to the teams during the
     practice time period. You probably only need one copy per team of this problem.
3.   All copies MUST be made single sided.
4.   The note on the front discusses balloons. As teams get questions correct they will get a balloon of the
     appropriate color. This maps the balloons to the colors.
5.   The lab phone number is 540-231-1832. The email address is on the cover letter.
6.   I will distribute electronic copies of the problems following the contest. You will get a copy by email
     if you want one. They will also be available on the Web.

My intention is to not release the test data or the solutions I have developed. I believe the test data is
correct, and have gone to the trouble of verifying by solution and by hand all of the solutions. However, I
still do not plan to release this information. This is simply a personal choice made by me. It has been
requested in the past, and has caused more problems than it was worth.

Please do not share any of the information contained in this packet with anyone until the contest begins.
This includes the number of questions.

I will talk to you the 14th.

Rob Chambers
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                               Problem # 1
November 14, 1998


                                             What’s my score?




Problem:
         Jack the caddie is responsible for keeping the scorecard for a golf foursome. On the scorecard, the players
         names appear at the top, each heading a column, and then each row will correspond to a hole in the
         match. The score the player receives on a hole should be placed in that player’s column in the row for the
         given hole. At each hole, he notices the order in which players tee off. The score of the first person to tee
         off is placed in the first column, the second person to tee off in the second column, the third person to tee
         off in the third column, and the last person to tee off in the fourth column. Unfortunately, his scoring
         method assumes players will always shoot in the same order on every hole as they did on the first hole.

         In reality, the golfers were rearranging themselves based on their score from the previous hole. The golfer
         with the lowest score on the previous hole shoots first on the following hole. If two golfers tied on the
         previous hole, the golfer that went earlier the hole before went earlier on this hole.

         Unfortunately, Jack did not realize his scoring mistakes until the 18th hole, and since there was a million
         dollar bet on the golf round, he needs to correct the scores, and fast!

         Write a program to read in the golf scores that Jack recorded, and create the corrected score card.

Input:
         The first 4 lines will contain the names of the four golfers. The order of the names will be the order they
         shot on the first hole. Each of the next 18 lines will contain the scores of the four golfers, in the order
         they shot on that hole.

         No name will contain more than 10 characters. The maximum score on any given hole will be 20.

Output:
         Print the scorecard for the golf round, giving each player the score they actually shot. The scorecard
         should take the following format:

             •    The names should appear at the top, all reading down the screen. Each of the names should end
                  on the same line. A line of dashes should appear between the names and the scores from the first
                  hole.

             •    Each line should then list the hole, and the score for each golfer, in the appropriate column.
                  After all 18 holes have been listed, another line of dashes should appear. The last line of output
                  should list the total score for each player, in the appropriate column.
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                                    Problem # 1
November 14, 1998


              •   If 2 or more columns are needed for any number (score, hole or total), the values should be right
                  justified.


Example:
 Input                                                                                   Output
                                                                                   J
                                                                                   a                                          J
Jason                                                                              s             J             R             o
Jim                                                                                o              i            o             h
Rob                                                                                n            m              b             n
John                                                       --------------------------------------------------------------------
4         6            3           2                                1              4             6             3             2
4         4            3           5                                2              3             5             4             4
4         4            4           4                                3              4             4             4             4
4         4            4           4                                4              4             4             4             4
4         4            4           4                                5              4             4             4             4
4         4            4           4                                6              4             4             4             4
4         4            4           4                                7              4             4             4             4
4         4            4           4                                8              4             4             4             4
4         4            4           4                                9              4             4             4             4
4         4            4           4                               10              4             4             4             4
4         4            4           4                               11              4             4             4             4
4         4            4           4                               12              4             4             4             4
4         4            4           4                               13              4             4             4             4
4         4            4           4                               14              4             4             4             4
4         4            4           4                               15              4             4             4             4
4         4            4           4                               16              4             4             4             4
4         4            4           4                               17              4             4             4             4
5         8            4           6                               18              5             6             4             8
                                                           --------------------------------------------------------------------
                                                                Total            72            77             71            74
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                                 Problem # 2
November 14, 1998


                                         The Unsinkable Ship?




Problem:
       The USS Unsinkable, which you were lucky (maybe) enough to get a ticket on, has tragically hit an
       iceberg. Suddenly the ship is going down, and you must find a way off of the ship, before your escape
       route is blocked. To make matters worse, there aren’t enough lifeboats for all of the passengers.

       As you make your way through the corridors (moving north, south, east and west), the boat will continue
       to flood, blocking sections which were previously usable. To safely make it out of the boat, you must
       locate a path which does not enter any flooded sections. You also must make it to the lifeboats before they
       are all filled with other passengers and dispatched into the sea (without you!).

       Write a program to determine a route out of the ship, reading in the layout and the current flood situation.

General Info:
       •   The lifeboats will fill at the rate of one lifeboat per 2 moves. The first lifeboat boat will fill after the
           second move.

       •   All lifeboats are located in the north west corner of the boat.

       •   If a section is bordered (either north, west, south or east) by a flooded section, that section will flood
           after A turns. The first automatically flooded section will occur after move A and before move A+1.

       •   Unflooded spaces adjacent to the newly flooded spaces will flood after A more spaces.

       •   You may not move into a section that will flood before the next turn unless it is the section with the
           lifeboat.

       •   You may not enter any section more than once.

       •   The map of the boat will have at most 20 columns and 20 rows.

       •   People move using Manhattan geometry only – no diagonal moves.
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                               Problem # 2
November 14, 1998



Input:
          The first Line will indicate how many sinking ships will be entered.
          For each sinking ship:
                    • the first line of the input will indicate how many lifeboats exist on the sinking ship
                    • the second line will indicate how quickly the sinking ship will flood (A)
                    • the third line of input will indicate how many rows make up the sinking ship map (M)
                    • the next M lines will indicate the layout of the ship and the flooding situation

          The following letters will appear in the layout:
                   O = Open
                   F = Flooded
                   Y = your starting location

Output:
          This program will first print “Sinking Ship #N” where N is the input set (start at 1). Starting on the next
          line, a map showing the path to the lifeboats (located in the north west corner), starting at your initial
          location (position 0), and ending at the lifeboats. A final diagram, indicating only the moves should be
          displayed. All sections which are not entered should be marked with an X. Each section should take up 3
          spaces in the final diagram. All numbers and letters should be right justified. If no path exists, this
          should simply output “No Path Exists.”. After printing a path or the message, a blank line should appear.
          After the last set is run a message, “All Sets Run.” should appear.

Example:
Input
          2
          5
          3
          3
          OOOOOF
          OOOOFF
          OFFYFF
          1
          1
          3
          OOF
          OFO
          FOY

Output:
          Sinking Ship #1
               5      4               3          2           X        X
               X      X               X          1           X        X
               X      X               X          0           X        X

          Sinking Ship #2
          No Path Exists.

          All Sets Run.
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                                Problem # 3
November 14, 1998




                                                     Joe-Ball
Problem:
         The National Joe-ball Association has received reports that teams may be padding their stars’ statistics in
         an effort to draw more attention to that player. It seems that some teams may be claiming that certain
         players had better statistics within a game than really happened. As a result a new program must be
         developed to determine all possible combinations of scores that a team may have obtained, in order to
         achieve the resulting final score.

         For those unfamiliar with Joe-ball, the scoring system is as follows:
              • Turnball = 6 pts.
              • Double Turnball = 14 pts.
              • Defensive Grumpling = 2 pts.
              • After each Turnball (but not Double Turnball), a team may earn one Extra Point.

         Each of the above listed scores are added to your final score throughout the game. For example, if during
         a game, a team scores two Double Turnballs and one Turnball, their total score would be 34 (14+14+6).

         Given a final score for any given team, there may be a number of scoring combinations. For example, the
         above listed final score of 34 can be the result of 2 Double Turnballs and 1 Turnball, 5 Turnballs and 2
         Defensive Grumplings, 17 Defensive Grumplings (etc…)

         Your jobs is to author the program that will calculate all of the different combinations of scoring, given a
         final score. You can assume that all final scores you receive will be zero or greater. All final scores are
         integer values. If no such combination exists, a message should be printed indicating such.

Input:
         The first line is an integer (N) that indicates how many scores need to be verified.
         The next N lines will indicate the total score from each game.

Output:
         For each game being analyzed, the first line of output should indicate:
                 • the game being analyzed (starting from 1) - “Game #N”
                 • the final score of the game - “X total points”
                 • and the total number of scoring combinations - “Number of possible combinations: C”

         Following the first line, a table should appear listing each possible scoring possibility. This table should
         look similar to the table below. For each possible combination, list the number of each scoring possibility
         in the appropriate column.

         At most 100 different combinations will be possible. All printed tables must be sized to fit in 80 columns.
         If no combinations are valid, a message stating “No possible combinations.” should be printed instead of
         the table.

         A blank line should appear after each analysis. After all of the games have been analyzed, a message
         stating “End of question 3.” should be printed.

         The output should be sorted from low to high in the following order: Double Turnballs, Turnballs,
         Defensive Grumpings, then Extra Points. If two combinations have a different number of Double
         Turnballs, the combination with fewer Double Turnballs should be listed first. If two combinations have
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                       Problem # 3
November 14, 1998



       the same number of Double Turnballs, the combination with fewer Turnballs should be listed first.
       Similarly if two combinations have the same number of Double Turnballs and Turnballs, the combination
       with fewer Defensive Grumpings should be listed first.

Example:
       Input file:
                 2
                 31
                 3

       Output to screen:
                Game #1      31 total points  Number of possible combinations: 9
                 Comb      Dbl. Turnball Turnball Def. Grumping    Extra Pts.
                 1         0              1        12              1
                 2         0              2        9               1
                 3         0              3        5               3
                 4         0              3        6               1
                 5         0              4        2               3
                 6         0              4        3               1
                 7         0              5        0               1
                 8         1              1        5               1
                 9         1              2        2               1

               Game #2   3 total points              Number of possible combinations: 0
               No possible combinations.

               End of question 3.
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                                Problem # 4
November 14, 1998


                                        No Hassle Car Insurance




The No Hassle Car Insurance Company has been losing sales over the past few years. As a result, the old CEO was
fired, and replaced by a younger, more technically advanced CEO.

The new CEO thinks that the company will make more money by firing half of its agents, and replacing them with
a web site, designed to give customers accurate quote information instantly. A new program must be developed to
read the customer information, and generate a quote for car insurance.

The No Hassle Car Insurance company believes that everyone deserves a second chance, and will not raise rates
after a customer has a first ticket and a first accident. More tickets or accidents than that, and the customer will
have to pay a premium. If a driver has more than 3 accidents or tickets, that driver is uninsurable.

The basic formula for the car insurance is:

                Rate = CARVAL * 0.019 * TICKET_MULT * ACCIDENT_MULT * AGE_MULT

Where:
         •   To calculate the value of the car (CARVAL), the purchase price of the car is required. Each year the
             car is owned, the value decreases by 10% of the previous year’s value. (A car that is 0 year old is
             valued at the purchase price.)
         •   A car has a minimum value of $3000.

         •   TICKET_MULT = (Number of Tickets) !

         •   ACCIDENT_MULT = (Number of Accidents) !

         •   The driver age multiplier (AGE_MULT) is as follows:

               Ages            Age Multiplier
               16-24           3
               25-34           1.5
               35-44           1
               45-64           1.5
               65+             3

A program should be developed which will take the purchase price of a car, the age of the car, the age of the driver,
the number of tickets and the number of accidents a driver has been involved in, and determine if a driver is
insurable, and if so, calculate an insurance rate for that driver.

Note: 0! = 1 and X! = X * (X-1)!
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                                Problem # 4
November 14, 1998



Input:
         The first line of input will indicate how many requests are being made (N). The next N lines of input
         contain the sticker price of the car, the age of the car, the age of the driver, the number of tickets and the
         number accidents that driver has been involved in. Each item will be separated by white space (tab or
         space characters).

         All input will be positive integers.

Output:
         For each line of input, the program should output “Request X:” where X is the request number (starting at
         1), followed by the cost of insuring that car. All output values should be rounded to 2 decimal places. If
         the driver cannot be insured, a message stating “The driver is uninsurable”.

         After all requests have been filled, a message “END OF OUTPUT should be printed.

Example:
         Input:
                   5
                   22000   3 26 2 0
                   12000   1 19 1 1
                   23679   3 44 3 1
                   37500   22 16 0 0
                   55000   12 18 6 1

         Output:
                   Request 1: $914.17
                   Request 2: $615.60
                   Request 3: $1967.87
                   Request 4: $210.49
                   Request 5: The driver is uninsurable.
                   END OF OUTPUT
        1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                        Problem # 5
        November 14, 1998

                                                    Oldies, but Goodies
Problem
        The Swinging Café has a new sound system to play the favorites from the 1950’s and 60’s. As a song is
        requested, it will locate the song in the stack of records (after all, these are from the 50’s and 60’s), and
        play the record. After the song is complete, the record will be placed on the top of the stack of records.
        At the end of the night, the manager prints out the new order of the records, and finds how many times
        each record was played during the day.

Input
        The first line of the input will contain the number of records contained in the sound system. (N < 100)

        The next N lines will contain the names of the songs in the sound system, starting with the top song. No
        song title will be more than 50 characters long.

        The remaining lines indicate which record was requested. (Input will terminate with end of file).

Output
        This program should print the final order of the records, starting at the top of the stack. After each record
        name, the number of times it was played during the day should be included.

        The record names should appear in a left justified column.

        The number of times played should appear in a right justified column.

        After the stack is printed, a line of dashes should appear. After the line of dashes, TOTAL should appear
        under the record names, and the total number of requests under the played column.

Example
        INPUT

        4
        Hello Dolly
        Goodbye
        Morning
        Night
        Hello Dolly
        Morning

        OUTPUT

        Morning                                 1
        Hello Dolly                     1
        Goodbye              0
        Night                           0
        -------------------------------------
        TOTAL                           2
        1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                    Problem # 6
        November 14, 1998


                                              The Ultimate Greed




Problem
        The Livingstone Lucky Lotto Organization has been playing the lottery for 50 years without winning even
        a free ticket. As a result of their poor performance, they decided to disband. From now on, if anyone
        wins they will keep the proceeds to themselves. When the lottery reached $500 million, the group sent a
        representative to buy one ticket for each member, but before the tickets could be distributed to everyone,
        the numbers were drawn, and one of the tickets was the only winner.

        Rather than split the money between them, everyone insists they had the winning ticket, so they should get
        to keep all $500 million. Eventually everyone in the group sued each other and a judge decided a fair way
        to split the proceeds.

        Everyone in the group would form a circle, and count aloud from one. The person who counts N would be
        eliminated, and the next person would start again at 1. The last person in the group would get the
        winning ticket.

        To ensure that you will win the ticket, you need a program to identify which position in the circle you
        want to have to ensure you will win. Given the size of the group, and the number to be eliminated (N),
        identify what space you need to have initially (the first person in the circle holds position 1).

Input
        Each line will indicate how many people are in the group (less than 100) and what number will be
        eliminated (N). Input terminates with end of file.
     1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                     Problem # 6
     November 14, 1998


Output
     For each set, a message indicating the set number (start at 1) and which starting position will win the
     ticket.

     After all data has been printed a message END OF OUTPUT should be printed.

Example
     Input
     52
     53

     Output
     Set #1: Position 3 wins the ticket.
     Set #2: Position 4 wins the ticket.
     END OF OUTPUT
1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                       Problem # 7
November 14, 1998


                                                  FIRE!




Montgomery County has just passed a stringent new fire code, which requires all restaurants to
demonstrate that anyone in the restaurant can evacuate within one minute. The fire department chief,
John Fire, has come up with a brilliant plan to test this for each restaurant. He maps out each restaurant
on a piece of graph paper. From this, he calculates how long it will take someone to walk out of the
restaurant from different seats. No person may start on, or walk through a table or wall.

You’ve been hired as a consultant for several restaurants to determine if they’re compliant before Chief
Fire arrives. They’ve provided you with graphs of their restaurants. You need to write a program to take
as input a graph of the floor plan and a list of locations of people on that graph, and calculate how long
each of them will take to enter a door.

Each graph consists of doors (D) and tables (T). You can assume that the border of the graph will consist
entirely of wall and doors, and that there are no doors anywhere other than on the border. To better reflect
how people move in restaurants, Chief Fire assumes that people can walk at different rates in aisles (a
space which does not have a table in any of the 8 bordering spaces) than in areas near tables.
Furthermore, each restaurant will have a different time needed for each type of space. Chief Fire also
assumes that people use Manhattan geometry when walking (no diagonal walking).

A person is considered to have exited the moment he or she enters a space with a door. People may not
enter spaces containing walls or tables. Patrons will not start on a wall, table or door. All restaurants will
have at least one path out.
        1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                         Problem # 7
        November 14, 1998


Input
        The first line of input will indicate the number of columns (X <= 50) and rows (Y <= 50) in the
        restaurant. Each value X and Y will include the row or column of walls and doors included in the
        restaurant graph. The rows will be numbered from 0 to Y – 1. Similarly the columns will be numbered
        from 0 to X –1.

        The next line of input will indicate the walking speed of people in aisles and non-aisles. These times are
        the time for a person to move out of an aisle or non-aisle space, regardless of the type of space moving
        into.

        The remaining input will contain the contents of the restaurant. Each line will begin with a letter
        identifying the type of object in the restaurant. T is table, D is door, and P is patron. All of the edge
        pieces not identified as doors will be walls. You may assume that all of the doors and tables in a
        restaurant will be listed before the first patron is listed. After the letter, the column and row of the item is
        listed. The input specification is 0 based. See the sample input for exact format.

        Input will terminate with end of file.

Output
        For each patron (in file order), a message stating “The patron located at position (COLUMN, ROW) will
        require N seconds to exit the building.” Column and Row should be filled in using the starting position.
        N should be the minimum walking time needed to exit the building.

        After all input has been processed, the message END OF OUTPUT should be printed.

        NOTE: The output for this problem must match exactly. This includes the spacing and the punctuation.

Example
        INPUT

        99
        12
        D48
        T33
        D02
        P46

        OUTPUT

        The patron located at position (4, 6) will require 2 seconds to exit the building.
        END OF OUTPUT
        1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech                      Problem # 8
        November 14, 1998

                                                     Smart VCR


Problem
        The Home Electronics division of IntelliMachine Corporation has decided to come out with a smart VCR.
        This VCR will be able to record shows by just knowing the show’s name.

        This technology is made possible because the VCR can query the television to determine which stations
        correspond to which channels, and it can go online to the networks and determine the date and time of all
        shows on a given station.

        The VCR should be turned off if it is not currently operating, as this saves electricity. If two shows on the
        same station, with one starting immediately after the other, are both being recorded, the VCR should not
        stop recording between them. If two shows, on different stations, with one starting immediately after the
        other completes, are being recorded, the VCR should stop recording, change channels, and then start
        recording again. In this case, the VCR should not be turned off. The VCR should not change channels to
        the channel it is currently on. The VCR will initially be turned off. It will be on channel 2 when first
        turned on.

        The following VCR commands are supported:

        TURN ON
        TURN OFF
        CHANNEL X – X is the channel to change to.
        RECORD – start recording
        STOP – stop recording.

Input
        The first line of input will indicate how many stations are available. (S <= 50)

        The next S lines will list the channel number and the name of the station. All station names will be
        strings of less than 10 characters long and contain no spaces.

        The next line of input will indicate the number of shows available. (T <= 100)

        The next T lines will indicate the name of the station followed by the start and stop time of the show, and
        the name of the show. Each show will be a string of fewer than 50 characters, and may contain spaces.
        (times will take the 24 hour format (0:00 to 23:59). All shows will occur within one day.

        The remaining lines of input will include the name of any show to be recorded. These may not be in the
        order they will be recorded.

        Input will terminate with END OF FILE.

        See sample input for exact format.

Output
        The output should list a set of commands to execute on the VCR. For each command, a time of the
        operation should be listed, followed by the action. All operations should be listed in the order they should
        occur. See the Example Output for the specific format.
     1998 ACM Mid Atlantic Programming Contest hosted by Virginia Tech   Problem # 8
     November 14, 1998

     After all commands are printed, END OF PROGRAM should be printed.

Example
     INPUT

     2
     33 ESPN
     61 ESPN2
     4
     ESPN 2:00 5:30 College Football – Notre Dame at Michigan
     ESPN2 9:00 10:00 Worlds Strongest Man 1997
     ESPN 16:30 17:00 News Hour
     ESPN 6:00 7:00 Cheerleading
     Cheerleading

     OUTPUT

     6:00 TURN ON
     6:00 CHANNEL 33
     6:00 RECORD
     7:00 STOP
     7:00 TURN OFF
     END OF PROGRAM

								
To top