Problem
Problem
Problem
th
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
5 4 1 3 5 6 7 10 3 1 2 3 4 5 6 7 8 9 10 [Sample Output] Case #1: 6: 1 Case #2: 15: 1 16: 1 17: 1 19: 1 21: 1 Case #3: 6: 1 7: 1 8: 2 9: 3 10: 4 11: 5 12: 7 13: 8 14: 9 15: 10 16: 10 17: 10 18: 10 19: 9 20: 8 21: 7 22: 5 23: 4 24: 3 25: 2 26: 1 27: 1
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
D. Winmine.exe
[Description] The Windows Minesweeper (WinMine) is one of the most well-known games on the Windows system. The rule is quite easy and it takes only a few minutes to play a set. First of all, lets briefly introduce this game (if you believe that you are familiar enough with this game, you can skip the next paragraph): The goal of the game is to uncover all the squares that do not contain mines (with the left mouse button) without being "destroyed" by clicking on a mine. The location of the mines is discovered by a process of logic. Clicking on the game board will reveal what is hidden underneath the chosen square or squares (a large number of blank squares may be revealed in one go if they are adjacent to each other). Some squares are blank but some contain numbers (1 to 8), each number being the number of mines adjacent to the uncovered square. The game is won once all blank squares have been uncovered without hitting a mine, any remaining mines not identified by flags being automatically flagged by the computer. The distinctive feature of minesweeper is the randomness at the initial stage and at some intermediate stages. ----Wikipedia Jaddy loves playing WinMine at free time very much due to its simplicity and ingenuity. However, sometimes it makes him frustrated when he reaches some undeterminable states during the game. See the following state as an example:
In the red circle of this example, the rest two squares are absolutely undeterminable and there are apparently two possible distributions of the rest ONE mine.
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
When Jaddy gets into this kind of trouble, he has no choice but to guess. Sometimes there are only two possible choices (as what the example says) but sometimes there are many. This way, he needs an assistant of this game to calculate the number of different possible distributions of mines depending on the current state of game board. This assistant of game is pretty useful and interesting, at least for him, so that he immediately starts coding. Unfortunately, Jaddy spent all the time to play WinMine in the class of Programming and Algorithm, so he feels such a complex task is a mission impossible. Jaddy loves WinMine very much so that he asks you, an excellent programmer, for help. In addition, in order to reduce the difficulty, he added two constraints: 1. It is guaranteed that the input state of game can always be created by making only ONE click on the initial board. 2. In the given state, if two unrevealed squares are connected directly or by any other unrevealed squares, they are also bi-connected. That is to say, even after any one of the other unrevealed squares is removed, these two squares are still connected. Here we say two squares are connected if and only if they share an edge. That means a square has at most four squares connected. Help Jaddy please! [Input] There are multiple test cases, the first line of input is a positive integer T (T <= 50) indicating the number of test cases. Then T cases follow. For each test case, the first line contains three positive integers n, m and w where 1 <= n, m <= 100 and 1 <= w <= 1000 denoting the number of rows and columns in the given board and the total number of mines on the board. Then an n*m matrix of chars describing the current state of board will be given. In this matrix, there are 2 styles of symbols: 1. digits from 0 to 8: that means the number of mines around this square (0 implies a blank square). 2. . (quotes for clarifying): that means this square is unrevealed. [Output] For each test case, output an integer leading by the case number, denoting the number of possible distribution of mine in the given state, module by 1000003. See the sample output for further details. [Sample Input]
6
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
2 4 5 2 ..... ..... 11111 00000 4 5 4 ..... ..... 22222 00000 [Sample Output] Case #1: 2 Case #2: 1
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
5. For each node of the BST, the graph of its left subtree and the graph of its right subtree do not share common columns in the picture of the whole tree. After the whole BST has been drawn, we number the rows from top to bottom, counting from 1, and so do the columns from left to right, counting from 1. Due to the large scale of the tree, the graph will become so large that it is impossible for Prof. Z to check every detail of the graph this time. So you are only asked to hand in m fragments of that graph to Prof. Z instead of the whole one. [Input] The first line contains T, the number of test cases. T test cases follow. For each test case: The first line contains a positive integer N (N <= 100000). The second line contains N distinct integers, each of which can be represented by a 32-bit signed integer. These numbers should be inserted into an empty BST one by one in the given order. The third line contains an integer M (M <= 5). M lines follow, each contains four integers, which are the row and column number of the top left corner, and the number of rows Ri and columns Ci of the required graph fragment, respectively. All the input integers will be positive and fit into a 32-bit signed integer, except Ri and Ci, which will be less than or equal to 200 and greater than 0. [Output] For each test case: Output the case number counting from 1 in the first line. Then M blocks follow, each contains Ri (or less, see next) lines. Each line should contain exactly Ci characters. Use space (ASCII 32) to fill in the blank. But if a line contains only whitespaces, this line should not be outputted. Output a blank line after each graph fragment. [Sample Input] 3 3 3 1 2 1 1 1 5 3
9
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
6 4 1 1 1 10 2 6 2 1 1 3 6
5 6 1 3 2 8 10 7 4 5 3 1 9 10 8 5 5 5 5
[Sample Output] Case #1: +-o | o+ | o Case #2: +--o+ | | o-+ o+ | | +o o | o Case #3: +o--| o +| +o+ o+ | o-+ | +o+
10
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
A can B: If X is A, then X has the ability to B. everything which can A can B: If X has the ability to A, X has the ability to B. everything which can A are B: If X has the ability to A, X is B. Questions Each question has one of the following forms: are noun_phrase noun_phrase? can noun_phrase verb_phrase? can everything which can verb_phrase verb_phrase? are everything which can verb_phrase noun_phrase? They are the question form of the statements. In each test case, the number of different noun phrases will not exceed 100; the number of different verb phrases will not exceed 100. [Output] For each test case, output two lines. The first line describes the test case number counting from 1, while the second line contains the same number of characters as the number of questions in this test case. Each character is either Y(denoting you can get that fact logically) or M(otherwise), without quotes. [Sample Input] 1 flies can fly. flies are insects. everything which can fly are animals. are everything which can fly insects? are flies animals? can flies eat? everything which can fly can eat. can flies eat? Bye! [Sample Output] Case #1: MYMY
12
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
0 1 0 0
13
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
14
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
10000]. See sample output for further details. Any answer with 10^-4 relative or absolute error is acceptable. [Sample Input] 2 3 0 1 0 3 2 3 3 4 0 1 1 0 4 2 3 3 2
0 1 2 1 0 2 0 0 1 1 2 2 3 3
16
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
I. Revenge of Fibonacci
[Description] The well-known Fibonacci sequence is defined as following: (0) = (1) = 1 () = ( 1) + ( 2) 2 Here we regard n as the index of the Fibonacci number F(n). This sequence has been studied since the publication of Fibonacci's book Liber Abaci. So far, many properties of this sequence have been introduced. You had been interested in this sequence, while after reading lots of papers about it. You think theres no need to research in it anymore because of the lack of its unrevealed properties. Yesterday, you decided to study some other sequences like Lucas sequence instead. Fibonacci came into your dream last night. Stupid human beings. Lots of important properties of Fibonacci sequence have not been studied by anyone, for example, from the Fibonacci number 347746739 You woke up and couldnt remember the whole number except the first few digits Fibonacci told you. You decided to write a program to find this number out in order to continue your research on Fibonacci sequence. [Input] There are multiple test cases. The first line of input contains a single integer T denoting the number of test cases (T<=50000). For each test case, there is a single line containing one non-empty string made up of at most 40 digits. And there wont be any unnecessary leading zeroes. [Output] For each test case, output the smallest index of the smallest Fibonacci number whose decimal notation begins with the given digits. If no Fibonacci number with index smaller than 100000 satisfy that condition, output -1 instead you think what Fibonacci wants to told you beyonds your ability. [Sample Input] 15 1 12 123
17
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
1234 12345 9 98 987 9876 98765 89 32 51075176167176176176 347746739 5610 [Sample Output] Case Case Case Case Case Case Case Case Case Case Case Case Case Case Case #1: 0 #2: 25 #3: 226 #4: 1628 #5: 49516 #6: 15 #7: 15 #8: 15 #9: 43764 #10: 49750 #11: 10 #12: 51 #13: -1 #14: 1233 #15: 22374
18
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
J. Quelling Blade
[Description] Mr. Sheep lost himself in a computer game. In this game, he plays the part of a super hero and fight with the evil. The equipment is very important in this game and Mr. Sheep thinks the Quelling Blade is the most powerful weapon. In this game, each type of weapon costs hero some money, and brings the hero benefits. If the hero buys two weapons (no matter they have the same type or not), the benefit values are accumulated. That is to say, if the hero buys two weapons with benefit 3 and 5, the hero will get total benefit value 8=3+5. There are some requirements for each weapon. If the hero wants to buy a certain weapon, he may need some other weapons first. For example, if hero wants to buy a Divine Rapier, he needs a Demon Edge and a Scared Relic. Of course, if he wants to buy the second Devine Rapier, he must buy another Demon Edge and another Scared Relic first. Notice that the existing weapon will not disappear after the trade. Note that a weapon may need multiple weapons with same type. And you may assume that a type of weapon is required by at most one other type of weapon. The hero is busy with combat and has no time to earn money. Fortunately, the game will give the hero 1 coin per second. So if the hero wants to buy a Quelling Blade, the minimum total time for him to achieve his goal can be easily calculated. Mr. Sheep is a perfectionist. He not only wants to get the Quelling Blade as soon as possible, but also wants to optimize every second during the game. He defines the utility of the game as the sum of the benefit value of the hero in each second. He calculates the utility from the start of the game until the second he gets Quelling Blade, exclusively. You may refer to the samples for further clarification. In the other words, you should define a way of process to buy the weapons for the hero, which minimize the total time to get Quelling Blade and optimize the utility of the game. [Input] There are hundreds of test cases, the number of test case are in the first line of the input. Notice that most of the test cases are relatively small. For each test case, the first line contains a single integer N denoting the number of different types of weapons. (1 <= N <= 1000) The next lines are describing the weapons. For each weapon, the first line contains two integers B and C, denoting the benefit value and the cost of this kind
19
The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University
of weapon. (1 <= B, C <= 2^31-1) Then a single integer P in the next line describes the number of requirements of this weapon. Next P lines, each line contains two integers I and A, means that this weapon needs A weapons of index I. The indexes of weapons are start from 1 to N. The Quelling Blade is the first type of weapon. And you may assume that the total numbers of weapons which are needed by the Quelling Blade is less than 1000000. Also notice that Quelling Blade can be brought in a finite game time and a type of weapon can be required by at most one other type of weapon. [Output] For each test case, output a single integer denoting the optimal utility. You may assume that the answer is fit in 64-bit signed integer. [Sample Input] 2 3 1 1 2 2 1 3 1 0 3 1 1 2 1 1 3 2 0
1 2 1 1 1
1 2 1 1 1
20