当前位置:文档之家› ACM竞赛试题(英文)

ACM竞赛试题(英文)

Problem A. Naughty fairies
Description
Once upon a time, there lived a kind of fairy in the world. Those fairies could hear the voice of fruit trees, and helped people with a harvest. But people didn’t know that fruits are also those fairies’ favorite food. After the fairies ate people’s 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 tree. 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. That’s why sometimes the number of fruits in a tree got increased after a fairy ate fruits of that tree.

But the fairies didn’t 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 couldn’t find the change of the number of peaches.

Suppose there were N peaches on a tree originally and 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 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 please tell Lily the least time she needs to change the number of visible peaches to N.
Input
There 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 left(0Output
For each test case, you should output just a number K indicating the minimum time (in minutes) Lily needed to finish her illusion magic.
Sample Input
5 2
1 99
86 32
0 0
Sample Output
2
98
12



Problem B. Prison Break
Description
Rompire 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 thinking 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 it’s 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 n×m little 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 e

nergy pool, Micheal#1 can use it to charge his battery ONLY ONCE. After the charging, Micheal#1’s 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 with 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 roof—then he can just fly away. 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 higher 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 charged at the beginning, Please tell him the minimum size of the battery needed for his Prison break.
Input
Input 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 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.
Output
For each test case, output one integer in a line, representing the minimum size of the battery Micheal#1 needs. If Micheal#1 can’t escape, output -1.
Sample Input
5 5
GDDSS
SSSFS
SYGYS
SGSYS
SSYSS
0 0
Sample Output
4


Problem C. To Be an Dream Architect
Description
The “dream architect” is the key role in a team of “dream extractors” who enter other’s 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 must 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 n×n×n blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked (1, 1, 1) 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 be eliminated once even if it is on multiple lines.

He

re is a sample graph according to the first test case in the sample input:

Input
The 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 <= 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=b
where axis_i (i=1, 2) is ‘X’ or ‘Y’, or ‘Z’ and axis_1 is not equal to axis_2. a and b are 32-bit signed integers.
Output
For each test case output the number of eliminated blocks.
Sample Input
2
3 2
Y=1,Z=3
X=3,Y=1
10 2
X=3,Y=3
Y=3,Z=3

Sample Output
5
19



Problem D. Gomoku
Description
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 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 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 don’t have a sharp mind. So I need a computer program to help me. What I want is 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 white 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.

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.
Input
The input contains no more than 20 cases.
Each case contains n+1 lines which are formatted as follows.
n
x1 y1 c1
x2 y2 c2
......
xn yn cn
The 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 stone 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 inp

ut is ended by n=0.
Output
For each test case:

First of all, the program should check whose turn next. Let’s 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 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 position of the move. If there are different moves to win, choose the one where x is the smallest. If there are still different moves, choose the one where y is the smallest.

2) Mr. Lucky’s opponent wins 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,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 Input
31
3 3 1
3 4 0
3 5 0
3 6 0
4 4 1
4 5 1
4 7 0
5 3 0
5 4 0
5 5 1
5 6 1
5 7 1
5 9 1
6 4 1
6 5 1
6 6 0
6 7 1
6 8 0
6 9 0
7 5 1
7 6 0
7 7 1
7 8 1
7 9 0
8 5 0
8 6 1
8 7 0
8 8 1
8 9 0
9 7 1
10 8 0
1
7 7 1
1
7 7 0
0
Sample Output
Place white at (5,8) to win in 3 moves.
Cannot win in 3 moves.
Invalid.



Problem E. Gunshots
Description
President 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 bullets. 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 terrorists 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 half-line. The bullet will be stopped by the first person it shoots. A person can be shot in three ways:
To simplify the problem, we assume that any two polygons can be completely separated 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 whic

h person has been shot by each bullet.
Input
There are multiple test cases in the input. The first line of the input file is an integer T demonstrating 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<=i
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 direction vector (dx, dy) of that gunshot.

In all test cases, we assume that 0< N<=100, 0Output
For 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 contains 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 Input
1
1
4
0 0
1 1
0 1
1 0
2
-1 0 1 0
-2 0 -1 0
Sample Output
HIT 0
MISS
*****

Hint
The figure of the first case in the samples is as follows:



Problem F. Rotational Painting
Description
Josh Lyman is a gifted painter. One of his great works is a glass painting. He creates some well-designed lines on one side of a thick and polygonal glass, and renders it by some special dyes. The most fantastic thing is that it can generate different meaningful paintings by rotating the glass. This method of design is called “Rotational Painting (RP)” which is created by Josh himself.

You are a fan of Josh and you bought this glass at the astronomical sum of money. Since the glass is thick enough to put erectly on the table, you want to know in total how many ways you can put it so that you can enjoy as many as possible different paintings hiding on the glass. We assume that material of the glass is uniformly distributed. If you can put it erectly and stably in any ways on the table, you can enjoy it.

More specifically, if the polygonal glass is like the polygon in Figure 1, you have just two ways to put it on the table, since all the other ways are not stable. However, the glass like the polygon in Figure 2 has three ways to be appreciated.

Pay attention to the cases in Figure 3. We consider that those glasses are not stable.

Input
The input file contains several test cases. The first line of the fil

e contains an integer T representing the number of test cases.

For each test case, the first line is an integer n representing the number of lines of the polygon. (3<=n<=50000). Then n lines follow. The ith line contains two real number xi and yi representing a point of the polygon. (xi, yi) to (xi+1, yi+1) represents a edge of the polygon (1<=i
Output
For each test case, output a single integer number in a line representing the number of ways to put the polygonal glass stably on the table.
Sample Input
2
4
0 0
100 0
99 1
1 1
6
0 0
0 10
1 10
1 1

相关主题
文本预览
相关文档 最新文档