1、第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest SessionThe 35th ACM-ICPC Asia Regional Contest (Hangzhou)Contest SectionOctober 24, 2010Sponsored by IBM & AlibabaZhejiang Sci-Tech UniversityThis problem set should contain 10 problems on numbered 24 pages.
2、 Please inform a runner immediately if something is missing from your problem set.第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 1 Problem A. Naughty fairiesDescriptionOnce upon a time, there lived a kind of fairy in the world. Those fairies coul
3、d hear the voice of fruit trees, and helped people with a harvest. But people didnt know that fruits are also those fairies favorite food. After the fairies ate peoples fruits, they always did something to cover it up.One day a little fairy named Lily flew into an orchard and found a large peach tre
4、e. Hungry as Lily was, she started eating without thinking until her stomach was full. In the fairy world, when a fairy ate the fruits in a fruit tree, sometimes the fruit tree would feel honored and bore more fruits immediately. Thats why sometimes the number of fruits in a tree got increased after
5、 a fairy ate fruits of that tree.But the fairies didnt want people to find out weird things such as fruits become more or less suddenly. Lily decided to use a magic spell so that the orchard owner couldnt find the change of the number of peaches.Suppose there were N peaches on a tree originally and
6、there were M peaches left after Lily was full. M may be greater than, less than or equal to N. All M peaches were visible at first, and Lily wanted to make an illusion so that exactly N peaches are visible.Lily can do 3 kinds of spell to change the total visible number of peaches:1) “PAPADOLA”:This
7、spell would increase the number of visible peaches by one.2) “EXPETO POTRONUM”:This spell would double the number of visible peaches.3) “SAVIDA LOHA”:This spell would decrease the number of visible peaches by one.Each spell would take one minute and Lily wanted to finish as fast as possible. Now ple
8、ase tell Lily the least time she needs to change the number of visible peaches to N.InputThere are several test cases, ended by “0 0”.For each test case, there are only one line containing two numbers separated by a blank, N and M, the original numbers of peaches and the numbers of peaches 第 35 届 AC
9、M 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 2 left(0N,M10500).There is no leading zero.OutputFor each test case, you should output just a number K indicating the minimum time (in minutes) Lily needed to finish her illusion magic.Sample Input5 21 9986 3
10、20 0Sample Output29812第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 3 Problem B. Prison BreakDescriptionRompire is a robot kingdom and a lot of robots live there peacefully. But one day, the king of Rompire was captured by human beings. His thin
11、king circuit was changed by human and thus became a tyrant. All those who are against him were put into jail, including our clever Micheal#1. Now its time to escape, but Micheal#1 needs an optimal plan and he contacts you, one of his human friends, for help.The jail area is a rectangle contains nm l
12、ittle grids, each grid might be one of the following: 1) Empty area, represented by a capital letter S. 2) The starting position of Micheal#1, represented by a capital letter F. 3) Energy pool, represented by a capital letter G. When entering an energy pool, Micheal#1 can use it to charge his batter
13、y ONLY ONCE. After the charging, Micheal#1s battery will become FULL and the energy pool will become an empty area. Of course, passing an energy pool without using it is allowed.4) Laser sensor, represented by a capital letter D. Since it is extremely sensitive, Micheal#1 cannot step into a grid wit
14、h a laser sensor. 5) Power switch, represented by a capital letter Y. Once Micheal#1 steps into a grid with a Power switch, he will certainly turn it off. In order to escape from the jail, Micheal#1 need to turn off all the power switches to stop the electric web on the roofthen he can just fly away
15、. Moving to an adjacent grid (directly up, down, left or right) will cost 1 unit of energy and only moving operation costs energy. Of course, Micheal#1 cannot move when his battery contains no energy. The larger the battery is, the more energy it can save. But larger battery means more weight and hi
16、gher probability of being found by the weight sensor. So Micheal#1 needs to make his battery as small as possible, and still large enough to hold all energy he need. Assuming that the size of the battery equals to maximum units of energy that can be saved in the battery, and Micheal#1 is fully charg
17、ed at the beginning, Please tell him the minimum size of the battery needed for his Prison break.InputInput contains multiple test cases, ended by 0 0. For each test case, the first line contains two integer numbers n and m showing the size of the jail. Next n lines 第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场
18、赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 4 consist of m capital letters each, which stands for the description of the jail.You can assume that 1=n,m=15, and the sum of energy pools and power switches is less than 15.OutputFor each test case, output one integer in a line, r
19、epresenting the minimum size of the battery Micheal#1 needs. If Micheal#1 cant escape, output -1.Sample Input5 5GDDSSSSSFSSYGYSSGSYSSSYSS0 0Sample Output4第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 5 Problem C. To Be an Dream ArchitectDescript
20、ionThe “dream architect” is the key role in a team of “dream extractors” who enter others dreams to steal secrets. A dream architect is responsible for crafting the virtual world that the team and the target will dream into. To avoid the target noticing the world is artificial, a dream architect mus
21、t have powerful 3D imagination.Cobb uses a simple 3D imagination game to test whether a candidate has the potential to be an dream architect. He lets the candidate imagine a cube consisting of nnn blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked (1, 1, 1)
22、 and the diagonally opposite block is marked (n, n, n). Then he tells the candidate that the blocks on a certain line are eliminated. The line is always parallel to an axis. After m such block eliminations, the candidate is asked to tell how many blocks are eliminated. Note that one block can only b
23、e eliminated once even if it is on multiple lines.Here is a sample graph according to the first test case in the sample input:InputThe first line is the number of test cases.In each test case, the first line contains two integers n and m( 1 = n = 1000, 0 = m 第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35t
24、h ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 6 = 1000).,meaning that the cube is n x n x n and there are m eliminations.Each of the following m lines represents an elimination in the following format:axis_1=a, axis_2=bwhere axis_i (i=1, 2) is X or Y, or Z and axis_1 is not equal to ax
25、is_2. a and b are 32-bit signed integers.OutputFor each test case output the number of eliminated blocks.Sample Input23 2Y=1,Z=3X=3,Y=110 2X=3,Y=3Y=3,Z=3Sample Output519第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 7 Problem D. GomokuDescription
26、You are probably not familiar with the title, “Gomoku”, but you must have played it a lot. Gomoku is an abstract strategy board game and is also called Five in a Row, or GoBang. It is traditionally played with go pieces (black and white stones) on a go board (19x19 intersections). Nowadays, standard
27、 chessboard of Gomoku has 15x15 intersections. Black plays first, and players alternate in placing a stone of their color on an empty intersection. The winner is the first player to get an unbroken row of five or more stones horizontally, vertically, or diagonally. For convenience, we coordinate the
28、 chessboard as illustrated above. The left-bottom intersection is (0,0). And the bottom horizontal edge is x-axis, while the left vertical line is y-axis. I am a fan of this game, actually. However, I have to admit that I dont have a sharp mind. So I need a computer program to help me. What I want i
29、s quite simple. Given a chess layout, I want to know whether someone can win within 3 moves, assuming both players are clever enough. Take the picture above for example. There are 31 stones on it already, 16 black ones and 15 white ones. Then we know it is white turn. The white player must place a w
30、hite stone at (5,8). Otherwise, the black player will win next turn. After that, however, the white player also gets a perfect situation that no matter how his opponent moves, he will win at the 3rd move. 第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Se
31、ssion 8 So I want a program to do similar things for me. Given the number of stones and positions of them, the program should tell me whose turn it is, and what will happen within 3 moves.InputThe input contains no more than 20 cases.Each case contains n+1 lines which are formatted as follows.nx1 y1
32、 c1x2 y2 c2xn yn cnThe first integer n indicates the number of all stones. n=222 which means players have enough space to place stones. Then n lines follow. Each line contains three integers: xi and yi and ci. xi and yi are coordinates of the stone, and ci means the color of the stone. If ci=0 the s
33、tone is white. If ci=1 the stone is black. It is guaranteed that 0=xi,yi=14, and ci=0 or 1. No two stones are placed at the same position. It is also guaranteed that there is no five in a row already, in the given cases.The input is ended by n=0.OutputFor each test case:First of all, the program sho
34、uld check whose turn next. Lets call the player who will move next “Mr. Lucky”. Obviously, if the number of the black stone equals to the number of white, Mr. Lucky is the black player. If the number of the black stone equals to one plus the numbers of white, Mr. Lucky is the white player. If it is
35、not the first situation or the second, print “Invalid.” A valid chess layout leads to four situations below:1) Mr. Lucky wins at the 1st move. In this situation, print :Place TURN at (x,y) to win in 1 move.“TURN” must be replaced by “black” or “white” according to the situation and (x,y) is the posi
36、tion of the move. If there are different moves to win, choose the 第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 9 one where x is the smallest. If there are still different moves, choose the one where y is the smallest.2) Mr. Luckys opponent wins
37、 at the 2nd move. In this situation, print:Lose in 2 moves.3) Mr. Lucky wins at the 3rd move. If so, print:Place TURN at (x,y) to win in 3 moves.“TURN” should replaced by “black” or “white”, (x,y) is the position where the Mr. Lucky should place a stone at the 1st move. After he place a stone at (x,
38、y), no matter what his opponent does, Mr. Lucky will win at the 3rd step. If there are multiple choices, do the same thing as described in situation 1. 4) Nobody wins within 3 moves. If so, print:Cannot win in 3 moves.Sample Input313 3 13 4 03 5 03 6 04 4 14 5 14 7 05 3 05 4 05 5 15 6 15 7 15 9 16 4
39、 16 5 16 6 06 7 16 8 06 9 07 5 1第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 10 7 6 07 7 17 8 17 9 08 5 08 6 18 7 08 8 18 9 09 7 110 8 017 7 117 7 00Sample OutputPlace white at (5,8) to win in 3 moves.Cannot win in 3 moves.Invalid.第 35 届 ACM 国际
40、大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 11 Problem E. GunshotsDescriptionPresident Bartlet was shot! A group of terrorists shot to the crowd when President Bartlet waved to cheering people after his address. Many people were shot by the irrational bull
41、ets. Senior FBI agent Don Epps takes responsibility for this case. According to a series of crime scene investigation, including analyzing shot shells, replaying video from closed-circle television and collecting testimony by witnesses, Don keeps all the information about where and how the terrorist
42、s shot to crowd, as well as the location of every single person when the gun shoot happened. Now he wants to know how many gunshot victims are there in this case.Imagine that each target person can be regarded as a polygon (can be concave or self-intersecting) and each gunshot can be regarded as a h
43、alf-line. The bullet will be stopped by the first person it shoots. A person can be shot in three ways: Person Person Person1. Normal shot 2. The bullets path is parallel to an edge3. The bullets path is tangent to an vertexTo simplify the problem, we assume that any two polygons can be completely s
44、eparated by a line. Also each start point of the gunshot can be separated from each polygon by a line. Now given M people and N gunshots, please work out which person has been shot by each bullet.InputThere are multiple test cases in the input. The first line of the input file is an integer T demons
45、trating the number of test cases. (T=10).For each test case, the first line is an integer N, representing the number of people (polygons). Following lines demonstrates the polygons. For the ith polygon (0=iN), the first line is an integer Qi, representing the number of edges of this polygon. In each
46、 of the following Qi lines, there are two real numbers xi and yi representing a point. Every pair of adjacent points demonstrate an edge of this polygon (i.e. (xi, yi) to (xi+1, yi+1) is an edge, in which 0=iQi-1), and (xQi-1, yQi-1) to (x0, y0) also demonstrates an edge of this polygon. 第 35 届 ACM
47、国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 12 Then there is a line contains an integer M representing the number of gunshots. In the following M lines, each line contains four real numbers x, y, dx and dy, representing the start point (x, y) and directi
48、on vector (dx, dy) of that gunshot. In all test cases, we assume that 0 N=100, 0Qi=1000, 0M=10000. OutputFor each test case, output contains M lines and the ith line demonstrates the result of the ith gunshot. If the ith gunshot shoots the jth polygon, the ith line contains “HIT j”, otherwise it con
49、tains a word “MISS” (means that it does not shoot any target). The polygons are numbered in the order of their appearance in the input file, and the numbers start from 0. At the end of each test case, please output a single line with “*”. Sample Input1140 01 10 11 02-1 0 1 0-2 0 -1 0Sample OutputHIT 0MISS*第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia Regional Contest (Hangzhou) Contest Session 13 HintThe figure of the first case in the samples is as follows:第 35 届 ACM 国际大学生程序设计竞赛亚洲区比赛(杭州)现场赛The 35th ACM-ICPC Asia