Problems Ulm
Problems Ulm
Input file: ambiguous.in Some programming contest problems are really tricky: not only do they require a different output format from what you might have expected, but also the sample output does not show the difference. For an example, let us look at permutations. A permutation of the integers 1 to n is an ordering of these integers. So the natural way to represent a permutation is to list the integers in this order. With n = 5, a permutation might look like 2, 3, 4, 5, 1. However, there is another possibility of representing a permutation: You create a list of numbers where the i-th number is the position of the integer i in the permutation. Let us call this second possibility an inverse permutation. The inverse permutation for the sequence above is 5, 1, 2, 3, 4. An ambiguous permutation is a permutation which cannot be distinguished from its inverse permutation. The permutation 1, 4, 3, 2 for example is ambiguous, because its inverse permutation is the same. To get rid of such annoying sample test cases, you have to write a program which detects if a given permutation is ambiguous or not. Input Specification The input contains several test cases. The first line of each test case contains an integer n (1 n 100000). Then a permutation of the integers 1 to n follows in the next line. There is exactly one space character between consecutive integers. You can assume that every integer between 1 and n appears exactly once in the permutation. The last test case is followed by a zero. Output Specification For each test case output whether the permutation is ambiguous or not. Adhere to the format shown in the sample output. Sample Input
4 1 4 3 2 5 2 3 4 5 1 1 1 0
Sample Output
ambiguous
the word "BULLSHIT" occurs only in uppercase letters every word has at most 25 characters, and each line has at most 100 characters there are at most 500 different words before a game ends the players follow the rules, so there is no need to check if a game is valid or not
Output Specification The output consists of one number: the average number of different words needed to win a game. Write the number as a reduced fraction in the format shown below. Reduced fraction means that there should be no integer greater than 1 which divides both the numerator and denominator. For example if there were 10 games, and the number of different words in each game summed up to 55, print "11 / 2".
Sample Input
Programming languages can be classified BULLSHIT into following types: - imperative and BULLSHIT procedural languages - functional languages - logical BULLSHIT programming languages - object-oriented BULLSHIT languages
Sample Output
9 / 2
Print the probability as a percentage with exactly 6 digits after the decimal point. The percentage value is considered correct if it differs by at most 10-6 from the judge output. Adhere to the format shown below and print one line for each test case. Sample Input
5 5 3 2 2 3 4 3 0 7 2 5 3 1 4 1 1 100 80 70 50 90 85 70
Sample Output
61.200000 percent
You can assume that 0 n 200 and 1 w, h 1000000. Moreover, all paintings already hanging do not overlap. Output Specification Produce one line of output for each test case. Write "Fail!" if there is no place left on the wall where the painting could be placed without overlapping other paintings. Otherwise, write the coordinates where the lower left corner of the painting should be placed. In case there is more than one solution, select the solution with a minimum y-coordinate, and break ties using the minimum x-coordinate. Sample Input
2 1 5 9 2 5 0 3 10 9 4 10 9 5 10 10 5 10 10 0 4 3 4
Sample Output
Fail! 4 0
Standard gauge:
1435 mm
Narrow gauge (meter gauge): 1000 mm A museum has trains from several countries. It needs tracks for every train type in order to show visitors the trains in use. However, since only one train is used at a time, a rail can be used by trains of different types. It follows that for n trains, each requiring a different railway gauge, n + 1 rails are sufficient (each train uses the leftmost rail and a rail that has exactly the required distance to it). But sometimes it is possible to save even more rails. Given the required railway gauges, your task is to construct a railway track that can be used by every train and requires the least number of rails. Note that a train can use any two rails, provided the distance between them is right. Input Specification The first line of the input file contains a number representing the number of test cases to follow. Each test case starts with an integer n (the number of different railway gauges required). The next line contains n integers between 1000 and 5000, each defining one required railway gauge. You can assume that 1 n 8. Moreover, for every test case in the input file, there will be a solution requiring at most 5 rails. Output Specification The output for each test case consists of three lines: The first line is of the form "Scenario #X", where X is the test case number starting with 1. The second line describes the solution your program has found; first your program should print how many rails are needed, followed by a colon, then the positions of each rail in increasing order (the first rail should be at position 0). The third line should be blank. If there are several solutions with the minimum number of rails, any one will do. Sample Input
3 4 1524 1520 1609 1435 3 1000 1520 1600 6 1000 2000 3000 4000 1500 2500
Sample Output
Scenario #1 4: 0 1520 1609 3044 Scenario #2 4: 0 1000 1520 1600 Scenario #3 5: 0 1500 3000 4000 5000
Input file: fool.in Surely you know someone who thinks he is very clever. You decide to let him down with the following problem:
"Can you tell me what the syntax for a set is?", you ask him. "Sure!", he replies, "a set encloses a possibly empty list of elements within two curly braces. Each element is either another set or a letter of the given alphabet. Elements in a list are separated by a comma." "So if I give you a word, can you tell me if it is a syntactically correct representation of a set?" "Of course, any fool can do it!" is his answer.
Now you got him! You present him with the following grammar, defining formally the syntax for a set (which was described informally by him):
Set Elementlist List Element Atom ::= ::= ::= ::= ::= "{" Elementlist "}" <empty> | List Element | Element "," List Atom | Set "{" | "}" | ","
<empty> stands for the empty word, i.e., the list in a set can be empty. Soon he realizes that this task is much harder than he has thought, since the alphabet consists of the characters which are also used for the syntax of the set. So he claims that it is not possible to decide efficiently if a word consisting of "{", "}" and "," is a syntactically correct representation of a set or not. To disprove him, you need to write an efficient program that will decide this problem. Input Specification The first line of the input file contains a number representing the number of lines to follow. Each line consists of a word, for which your program has to decide if it is a syntactically correct representation of a set. You may assume that each word consists of between 1 and 200 characters from the set { "{", "}", "," }. Output Specification Output for each test case whether the word is a set or not. Adhere to the format shown in the sample output. Sample Input
4 {} {{}} {{}},{,}} {,,}
Sample Output
Word Word Word Word #1: #2: #3: #4: Set Set Set No Set
In each round, each remaining team plays at most one game If there is an even number of remaining teams, every team plays exactly one game If there is an odd number of remaining teams, there is exactly one team which plays no game (it advances with a wildcard to the next round) The winner of each game advances to the next round, the loser is eliminated from the tournament If there is only one team left, this team is declared the winner of the tournament
As can be proved by induction, in such a tournament with n teams, there are exactly n - 1 games required until a winner is determined. Obviously, after round 1, teams may already have been eliminated which should take part in another game. To prevent this, for each game you also have to tell which team should win. Input Specification The input file contains several test cases. Each test case starts with an integer n (2 n 1000), the number of teams participating in the tournament. The following n lines contain the names of the teams participating in the tournament. You can assume that each team name consists of up to 25 letters of the English alphabet ('a' to 'z' or 'A' to 'Z'). Then follow n - 1 lines, describing the games the sheikh would like to see (in any order). Each line consists of the two names of the teams which take part in that game. You can assume that it is always possible to find a tournament schedule consisting of the given games. The last test case is followed by a zero.
Output Specification For each test case, write the game schedule, distributed in rounds. For each round, first write "Round #X" (where X is the round number) in a line by itself. Then write the games scheduled in this round in the form: "A defeats B", where A is the name of the advancing team and B is the name of the team being eliminated. You may write the games of a round in any order. If a wildcard is needed for the round, write "A advances with wildcard" after the last game of the round, where A is the name of the team which gets the wildcard. After the last round, write the winner in the format shown below. Print a blank line after each test case. Sample Input
3 A B C A B 5 A B C D E A C A C 0
B C
B D E E
Sample Output
Round #1 B defeats A C advances with wildcard Round #2 C defeats B Winner: C Round #1 A defeats B C defeats D E advances with wildcard Round #2 E defeats A C advances with wildcard Round #3 E defeats C Winner: E
The empty tree which has no node at all is a binary search tree Each non-empty binary search tree has a root, which is a node labelled with an integer, and two binary search trees as left and right subtree of the root A left subtree contains no node with a label than the label of the root A right subtree contains no node with a label than the label of the root
Given such a binary search tree, the following search procedure can be used to locate a node in the tree: Start with the root node. Compare the label of the current node with the desired label. If it is the same, you have found the right node. Otherwise, if the desired label is smaller, search in the left subtree, otherwise search in the right subtree. The access cost to locate a node is the number of nodes you have to visit until you find the right node. An optimal binary search tree is a binary search tree with the minimum expected access cost. Input Specification The input file contains several test cases. Each test case starts with an integer n (1 n 50), the number of nodes in the optimal binary search tree. For simplicity, the labels of the nodes will be integers from 1 to n. The following n lines describe the structure of the tree. The i-th line contains the labels of the roots of the left and right subtree of the node with label i (or -1 for an empty subtree). You can assume that the input always defines a valid binary search tree. The last test case is followed by a zero. Output Specification
For each test case, write one line containing the access frequency for each node in increasing order of the labels of the nodes. To avoid problems with floating point precision, the frequencies should be written as integers, meaning the access probability for a node will be the frequency divided by the sum of all frequencies. Make sure that you do not write any integer bigger than 263 - 1 (the maximum value fitting in the C/C++ data type long long or the Java data type long). Otherwise, you may produce any solution ensuring that there is exactly one optimal binary search tree: the binary search tree given in the input. Sample Input
3 -1 -1 1 3 -1 -1 10 -1 2 -1 3 -1 4 -1 5 -1 6 -1 7 -1 8 -1 9 -1 10 -1 -1 0
Sample Output
1 1 1 512 256 128 64 32 16 8 4 2 1
Note that the first test case in the sample input describes a tree looking like
1 2 / \ 3