UTD Division II Programming Contest August 16th 2003 For

Document Sample
UTD Division II Programming Contest August 16th 2003 For Powered By Docstoc
					UTD Division II Programming Contest August 16th 2003                                      1


             UTD Division II Programming Contest
                      August 16th 2003
                       For Undergraduates

Rules
  1. Time allowed 4.5 hours.

  2. Answer the questions in any order.

  3. Use only Java or C/C++.

  4. You must not use any OS-specific packages, such as MFC or Windows API.

  5. If you use a *.h file that is not readily available on all PCs in the lab, for
     example stdAfx.h, you must supply it.

  6. If you use a Unix compiler, state the server name and the compiler com-
     mand line.

  7. Each program will be given no more than two minutes of running time.

  8. Your program must read from the standard input and write to the standard
     output - it must work with the “<” and “>” file redirection arguments when
     run in a DOS or Unix window, no exceptions.

  9. Name your source and executable with your team name (or a sensible part
     of it) followed by the problem number, i.e. toads3.cpp, etc.

 10. do not use solutions from the web or from text books. Your solutions should
     be entirely yours, developed in their entirety during the time allowed for
     the contest

 11. email me (ivor@utdallas.edu) with questions during the period 1pm to 4pm).

 12. Submit your solutions as a zip file attachment to an email to: ivor@utdallas.edu
     by: 6pm today.

Scoring
Equal points will be awarded to each question, even though they may not be equally difficult.
In order to break ties, we will consider the algorithm(s) used and their ability to scale to
large problems.
The final results may not be available until after the weekend.
UTD Division II Programming Contest August 16th 2003                                     2


  1. Eventual Palindromes
     Consider the decimal number 193. Reverse its digits and add the result to the starting
     number. The answer is 193 + 391 = 584. Repeat the process, 584 + 485 = 1,069.
     Continue the process until a palindrome is formed (a number that is the same when
     read in the forward or reverse directions). In this example, the palindrome is 233332,
     formed after eight applications of the “reverse and add” rule. All numbers are thought
     to yield palindromes eventually, although there is no proof of this, and, for some
     numbers, no palindrome has ever been found. Your task is to determine, for each
     input number, how many applications of the “reverse and add” rule are necessary to
     form a palindrome, and to find the palindrome.
     Assume that no input number will be larger than 10,000. You can also assume that no
     palindrome will be larger than 4,668,731,596,684,224,866,951,378,664. If a palindrome
     has not been formed within 1,000 iterations, abandon the search and print the line of
     text beginning with the input number being tested, then a space character, then the
     string “No palindrome was found after 1,000 iterations”.
     Input:
     A number P on a line by itself giving the number of data sets to follow and, for each
     data set, a line containing the number N to be tested.
     Output:
     For each data set, a line containing three space separated integers: the input number,
     then the number of iterations, then the palindrome.
     Example Input:

     5
     193
     21
     111
     462
     1097

     Example Output:

     193 8 233332
     21 1 33
     111 0 111
     462 3 4884
     1097 1 8998
UTD Division II Programming Contest August 16th 2003                                       3


  2. Inate that Page!
     Your program will read a block of plain English text and alter the layout of the text
     according to the following rules.

       a The input text is a short piece of prose terminated by the end of file character. The
         text follows the normal conventions for punctuation. Commas, colons, semicolons,
         and periods immediately follow printing characters. One or more spaces or a
         newline always follows one of these punctuating characters.
       b The only non-printing characters present in the input are space characters, new-
         lines, and the end of file character.
       c In the output text, commas, colons, semicolons and periods must be followed by
         a single space or a newline character.
       d When two consecutive newline characters appear in the input text, a paragraph
         break is indicated. In the output text, two paragraphs are separated by a blank
         line and the first sentence of a new paragraph must be preceded by six spaces.
       e The first sentence of the output text begins a new paragraph and must therefore
         begin with six spaces.
        f Within paragraphs, each line of output text must contain as many space-separated
          words of text as possible to fill the 80 character width of the paper without
          breaking words into two.

     Input:
     A single block of text terminated by an end of file character.
     Output:
     The corresponding paginated output.

                        Problem 2 is continued on the next page
UTD Division II Programming Contest August 16th 2003                                    4


     Problem 2 continued:
     Example Input:

     Programming contests enrich my life   in so many ways. I wake up each
     morning crossing off the days on my   wall
     calendar until the next contest day   comes round.
     When the day of the contest finally   arrives,
     I get up early, open my programming   and my Data-Structures text books.
     By the time the contest begins, I’m   ready to
     rock and roll.

     My two team mates are always late.
     Invariably, we have arguments about
     which problem to
     tackle first, and we usually misread the problems and forget some of
     the boundary conditions.

     We get pretty good results, considering the two dummies I have to work
     with, and the difficulty of the problems. Dr.
     Page wants us to win that ACM Regional Contest so he can go to Hawaii,
     or wherever the world finals are this year.
     I’ll make him proud one of these days.

     Guide:

              1         2         3         4         5         6         7         8
     12345678901234567890123456789012345678901234567890123456789012345678901234567890

     Example Output:

           Programming contests enrich my life in so many ways. I wake up each
     morning crossing off the days on my wall calendar until the next contest day
     comes round. When the day of the contest finally arrives, I get up early, open
     my programming and my Data-Structures text books. By the time the contest
     begins, I’m ready to rock and roll.

           My two team mates are always late. Invariably, we have arguments about
     which problem to tackle first, and we usually misread the problems and forget
     some of the boundary conditions.

           We get pretty good results, considering the two dummies I have to work
     with, and the difficulty of the problems. Dr. Page wants us to win that ACM
     Regional Contest so he can go to Hawaii, or wherever the world finals are this
     year. I’ll make him proud one of these days.
UTD Division II Programming Contest August 16th 2003                                          5


  3. Bulk Up!
     An organization that wishes to make a large mailing can save postage by following
     U.S. Postal Service rules for a bulk mailing. Letters in zip code order are bundled into
     packets of 10-15 letters each. Bundles may consist of letters in which all 5 digits of
     zip code are the same (5-digit bundles), or they may consist of letters in which only
     the first 3 digits of zip code are the same (3-digit bundles). If there are fewer than 10
     letters to make up a bundle of either type, those letters are mailed first class.
     You are to write a program to read a data set of zip codes, one per line, until end of file.
     Your program should count the number of 5-digit bundles, 3-digit bundles, and first
     class letters. You should include as many letters as possible in 5-digit bundles first,
     then as many as possible in 3-digit bundles, with as few bundles of 10 to 15 letters as
     possible. For example, if there are 31 letters with the same zip code, they must be
     combined into exactly three 5-digit bundles of sizes 11, 10, and 10. For 36 letters with
     the same zip code, there would be 3 5-digit bundles of sizes 15, 11, and 10. Don’t be
     concerned about how the letters are partitioned into bundles. You only have to decide
     on the number of bundles.
     Not all zip codes in the data set will be valid. A valid zip code consists of exactly 5
     digits (0-9), all of which cannot be 0. Non-numeric characters are not allowed. At the
     end of your output, print the invalid zip codes found. (Duplicates must only be printed
     once.)
     Output a report that lists 5-digit zip code bundles first, with the number of letters
     and number of bundles for each zip code. Next list all 3-digit zip code bundles with
     the same two counts, followed by all zip codes that are not bundled and to be sent
     first class. At the end print totals of letters and bundles, followed by the number of
     invalid zip codes and a list of these. Single space the report, and print blank lines
     following the heading, before the total line, and between the three groups of zip codes.
     For 3-digit bundles, print the zip codes in the form dddxx, where ddd represents the
     three significant digits and xx represents the last two digits to be omitted. Your output
     should be similar to that shown in the sample.
     Input:
     A single data set comprising a list of potential zip codes, one per line, possibly con-
     taining some erroneous codes, as explained above.
     Output:
     See the description above and the Sample Output below.

                         Problem 3 is continued on the next page
UTD Division II Programming Contest August 16th 2003                               6


     Problem 3 continued:
     Example Input:
      95864    95826
      95864    95826
      95864    95826
      95867    95826
      95920    95826
      9j876    95826
      95616    95827
      95616    8976
      95747    95833
      95814    95833
      95818    95833
      95818    95833
      8976     95819
      95818    95819
      95818    95819
                         NOTE: The actual input will have one zip code per line.
      95819    95819
      95819    95833
      00000    95833
      95819    95833
      95819    95864
      95819    95864
      95819    95864
      95819    123456
      95825    95864
      95825    95864
      95825    95864
      95825    95864
      95825
     Example Output:
     ZIP        LETTERS       BUNDLES

     95819        11             1
     95864        10             1

     958xx        25             2

     95616         2             0
     95747         1             0
     95920         1             0

     TOTALS       50             4

     INVALID ZIP CODES
     9j876
     8976
     00000
     123456
UTD Division II Programming Contest August 16th 2003                                       7


  4. Pesky Prefixes
     An encoding of a set of symbols is said to be immediately decodable if no code for one
     symbol is the prefix of a code for another symbol. We will assume for this problem
     that all codes are in binary, that no two codes within a set of codes are the same, that
     each code has at least one bit and no more than ten bits, and that each set has at least
     2 codes and no more than 64.
     Examples: Assume an alphabet that has symbols A, B, C, D
     The following code is immediately decodable:
     A:01 B:10 C:0010 D:0000
     but this one is not:
     A:01 B:10 C:010 D:0000 (Note that A is a prefix of C)
     Write a program that accepts as input a series of data sets containing the codes. For
     each data set, your program should determine whether the codes in that data set
     are immediately decodable, and should print a single output line giving the data set
     number and stating whether the group is, or is not, immediately decodable.
     Input:
     There are several data sets, the final data set is terminated by an end of file character.
     Each record in a data set contains a collection of zeroes and ones representing a binary
     code for a different symbol. Each data set is followed by a single separator record
     containing a single 9; the separator records are not part of the group. Each group is
     to be processed independently.
     Output:
     A single line of output for each data set as follows: “Set # is immediately decodable,”
     or “Set # is not immediately decodable,” where # is the data set number, beginning
     at 1.
     Example Input:

     01
     10
     0010
     0000
     9
     01
     10
     010
     0000
     9

     Example output:

     Set 1 is immediately decodable
     Set 2 is not immediately decodable
UTD Division II Programming Contest August 16th 2003                                        8


  5. Don’t get cross now!
     A well-known problem in Computer Graphics is to determine if two line segments
     intersect. In this problem you must write a program to report any intersections between
     pairs of line segments from a large set of two dimensional line segments. Here is a
     helpful definition:

          Two line segments intersect if there exists a point (x, y) that is on both line
          segments, including their endpoints.

     In simple terms, two line segments intersect if they touch or cross.
     Input:
     A single integer N on a line by itself giving the number of data sets to follow. Then,
     for each data set, an integer M, 0 < M ≤ 200 on a line by itself giving the number
     of line segments in that data set, followed by M lines, each containing four integers,
     separated by single spaces, giving the end points of the M line segments in the order
     x1 , y1 , x2 , y2 . All endpoint values will be in the range −100 to +100 inclusive.
     Output:
     For each data set, a line of text of form, “Data Set #”, where # is the data set
     number, beginning at 1, then the line of text “There are no intersections,” or a list
     of (x, y) intersection points, printed to 6 figure accuracy. Each intersection should be
     reported on a line by itself and space separated. If two line segments are overlapping
     sub segments of the same infinite line, you should report the point (x, y) that is at the
     center of the overlap region (see the second data set below).
     The intersections should be reported in increasing order of their x coordinated and, if
     there are several intersections with the same x coordinate, those intersections must be
     reported in increasing order of their y coordinate.

                         Problem 5 is continued on the next page
UTD Division II Programming Contest August 16th 2003   9


     Problem 5 continued:
     Example Input:

     4
     4
     0 10 4 8
     5 0 8 3
     10 10 4 9
     8 0 5 3
     2
     0 0 5 5
     4 4 10 10
     2
     1 2 3 4
     3 4 1 6
     2
     1 1 5 6
     7 8 9 10

     Example Output:

     Data Set 1
     4.0 9.0
     7.0 1.5
     Data Set 2
     4.5 4.5
     Data Set 3
     3.0 4.0
     Data Set 4
     There are no intersections
UTD Division II Programming Contest August 16th 2003                                      10


  6. Pulling Your Weight
     At the CS department’s annual picnic a “tug of war” contest is to be held. The winning
     team members will each be awarded the book entitled, “How to lose weight quickly.”
     There are M participants and each one of them must be placed on one of the two
     teams. The numbers of members of the two teams must not differ by more than 1.
     Finally, the total weights of the members of the two teams must be as close as possible.
     Input:
     A single integer N on a line by itself giving the number of data sets to follow. Then,
     N data sets, each beginning with an integer M on a line by itself giving the number of
     participants, followed by M lines giving the integer weights in lbs of the participants.
     No data set will contain more than 30 participants.
     Output:
     For each data set, a single line of output giving the total weights of the two teams,
     separated by a single space.
     Example Input:

     1
     3
     100
     90
     200

     Example Output:

     190 200

				
DOCUMENT INFO