Problem 1: Map Check: Input!
Problem 1: Map Check: Input!
Great County Comprehensive Internet Services (GCCIS), a leading local provider of information technology, is planning a new network. Each server will be connected to a certain number of clients which will be located exactly north, south, east, or west of their server. Lines will connect the server to one or more clients located in the same direction away from the server, but may not cross each other or pass through another server or client served by another server; a server may have lines extending into any number of the four directions. The administration of GCCIS does not believe that its employees are apt enough to produce a correct network map and have turned to you for help. You have been asked to write a program which can validate a map proposal. Input! see le ~/1.txt Input to your program is a map specication immediately followed by a map proposal consisting of lines with positive integers, single-letter server names, and periods, separated by white space. The input below corresponds to the map shown next to it:
6 A B C D E F D D D . F 5 2 1 2 4 3 5 A . E D F 5 2 4 5 1 3 4 E E . E F 1 2 3 4 5 4 . B E F .
B . C C C
The rst line contains s, the number of servers ( 52), followed by r and c, the number of rows and columns in the map grid (each 25). Rows and columns will be numbered top-down and left-to-right, beginning with one. Each of the next s lines contains a server name, the row and column number where the server is located in the grid, and the number of clients which the server should be connected to. The next r lines contain c words each, which form the map proposal. Each word is either a server name to represent a client connected to that server, or a period to represent a server in the location specied earlier, or a minus sign if the location contains neither a server nor a client. Output Output from your program should be one line with one of the words yes or no, depending on whether the map proposal satises the specication or not. For the example:
yes
As in problem 1, the rst line contains s ( 52), the number of servers, followed by r and c, the number of rows and columns in the map grid (each 25). Rows and columns will be numbered top-down and left-to-right, beginning with one. Each of the next s lines contains a server name, the row and column number where the server is located in the grid, and the number of clients which the server should be connected to. Output Output from your program should be a map proposal consisting of r lines containing c words each, separated by single blanks. Each word is either a server name to represent a client connected to that server, or a period to represent a server in the location given by the map specication, or a minus sign if the location contains neither a server nor a client. For the input above:
D D D . F A . E D F E E . E F . B E F . B . C C C
The input will always be a valid specication; therefore, the output should always be a valid proposal as described in problem 1. Note that if you concatenate an input and the corresponding output for this problem you get an input for problem 1 which should produce the output yes.
The falling factorial function suggests a new way to write polynomials, namely as integer combinations of falling factorial functions. For example, here are some polynomials and their falling factorial forms: x3 - 3 x2 + 2 x = x[3] 3 x2 - 3 x = x = x3 3 x[2] x[1]
The rst three examples are just the falling factorial functions dened above, the last example results by adding the rst three. You are expected to write a program which reads the coefcients of polynomials and outputs the coefcients of their falling factorial forms. Input
0 0 0 0 7 2 -3 1 -3 3 1 0 0 1 0 5 1
see le ~/3.txt
Input to your program consists of lines with 25 integers, separated by white space:
Each line denes the coefcients of one polynomial, starting with the constant coefcient. Output For each input line there should be one output line with the coefcients of the falling factorial form, starting with the coefcient of x[0]. For the input above:
0 0 0 0 7 0 0 1 1 6 0 1 3 3 1 8 1
Problem 4: Grafti
While on a walk our robotic friend Dezider nds a rather peculiar drawing. The drawing consists of numbers in a 3x3 grid. Each cell in the grid appears to contain a single digit:
Upon closer examination Dezider discovers that some of the cells originally contained 2-digit numbers. Apparently someone has painted over some of the digits in the drawing, preserving just one of the original digits in each cell. A passerby mentions to Dezider that originally the sum of the numbers in each row and each column was exactly 100 and that there had not been leading zeros. Dezider would like to restore the drawing to its original form but cannot determine the values of the missing digits. He has asked you to write a program to determine them. Input see le ~/4.txt The input contains three lines, each line species one row of the grid. Each line contains three single digits, separated by white space. For example:
4 7 8 5 1 4 8 2 5
Output If it is possible to nd the missing digits, the output consists of the three lines of a restored grid (which need not be unique). Each line contains three one- or two-digit numbers, separated by single spaces. For the example above:
14 78 8 58 1 41 28 21 51
If no solution exists, the program should output one line with the text No solution . For example, for the input
1 5 7 2 4 5 1 7 0
Each line contains the numerator followed by the denominator of a non-negative rational number. The denominator will not be zero and the number of repeating digits will not exceed 100 digits. Output For each input line there should be one output line with two numbers, separated by one blank, describing the decimal expansion of the rational number. For the input above:
0. 3 142. 857142 7.1 243 12.3 0
The rst number must contain or end with a decimal point and must be the prex of the expansion with all those digits (at least up to the decimal point) which are not repeated. The second number must consist of one or more digits, must be the recurring part of the expansion, must be as short as possible, and must not be just a single nine.
Filip, just one year old, suspects that he needs a bit of help. So, he is asking you to write a program that tells him which route to take to collect the largest possible number of raisins. Input see le ~/6.txt Input to your program consists of lines with non-negative integers, separated by white space:
3 0 1 0 5 2 5 0 6 2 0 3 7 0 2 8 0
The rst line contains r and c, the number of rows and columns in the grid (each 1000). Each of the next r lines contains c numbers, the number of raisins on each tile in one row of the grid (each 1000). The race starts in the northwest corner, i.e., rst column of the rst row; this tile contains no raisins. The race ends in the last column of the last row no raisins there, either. Output Output from your program should be one line with a number and a string, separated by a single space:
16 EESESE
The number denes how many raisins are on the path and the string denes the path with each move designated by a letter (E for east and S for south). The string length will be r + c - 2.
Busters friend Arnie loves arithmetic and after Buster lls in one of his grids, Arnie computes the sum of the numbers in each column (in the grid above Arnies sums appear below the grid in the row that is shaded gray). One day over dog biscuits Arnie suggests to Buster that another way to play the game would be to start out with the sums and then ll in the grid, using the same rules as before, so that sum of the digits in each column match the sums. Heidi and Sammy, while waiting for the next set of dog biscuits, overhear this conversation. They decide that it is possible to write a program that, given the size of the grid and the sums, lls in the grid if possible. Once they settle on an algorithm they realize that between napping, protecting the house, and walking, they do not have time to write the program. So, they decide to outsource the project to you. Input see le ~/7.txt Input to your program consists of positive integers, separated by white space. The rst line contains two integers, r and c, the number of rows and columns of the grid to be lled (each 15). The second line contains c integers each is the sum of the digits
in the corresponding column of the grid. (These sums add up to 100.) For the example above:
7 10 4 11 4 13 5 20 6 17 6 14
Output Your output is either a single line with No solution. or the grid of digits, r lines with c characters each, where you represent each cell of the grid by a digit or a period. For the example above:
1.2.3.4.5. ...6.7.8.9 10........ ..11..12.. 13..14..15 ..16..17.. 18..19....
Problem 8: Gothic
What does blood have to do with a party? Very simple:
blood brood brook brock broch broth booth booty borty porty party
This is a sequence of minimal length, taken from the 233614 words in Webster's Second International Dictionary, which starts with blood and ends with party and where two successive words differ by exactly one letter. Your job is to compute such sequences. Input see le ~/8.txt The rst line of input contains a positive integer n. Each of the next n lines contains two words separated by white space. The remaining lines of the input contain all words from Webster's Second International Dictionary. For this problem words consist of lower-case letters from a to z . For example:
5 blood party barn burr aal aam bottom bottom automotive laboratory a aa aal aalii aam aani
Output The output must consist of n lines, each one discussing one pair of words in the input: a line must contain a single word from the dictionary equal to both input words; a minimal-length sequence of dictionary words as described above, separated by single blanks starting with the rst input word and ending with the second; or the statement cannot morph word into word. For the input above:
blood brood brook brock broch broth booth booty borty porty party barn burn burr aal aam bottom cannot morph automotive into laboratory