USACO Summary: Bronze Problem # 5 (Source Code Included)

On a large chessboard there are two groups of chesses. One group will move horizontally from west to east ( 0 degree direction), and the other group will move vertically from south to north (90 degree direction). Each piece will move forward one cell at a time from its current location and mark this cell as occupied. If two pieces move into the same cell at the same time, both of them could pass safely. If a piece moves into a cell already marked occupied by another chess, this piece will be stuck there.

Give a list of pieces (direction 0 for moving east, direction 90 for moving north). Find out how many cells each piece could move forward. If a piece could move unlimited cells then mark it as “N/A”.

Sample Input: input.txt

6
0 3 5
90 5 3
0 4 6
0 10 4
90 11 2
90 8 1

For the sample input, first line 6 indicates there are six pieces. Starting from second line, each line contains 3 numbers, first number is the direction (0 or 90). The next two numbers mark the (x, y) coordinates on the chessboard for this piece.

Sample Output: output.txt

5
3
N/A
N/A
2
5

USACO编程竞赛概要:铜级题 # 5

在一个非常大的棋盘上面有两组棋子,一组沿水平方向从西往东移动(0°坐标方向),另外一组沿垂直方向从南往北移动(90°坐标方向)。所有棋子都同时移动,每个棋子每次都只能移动一格,并且把经过的格子标注为已占用。如果两个棋子同时进入一个格子,那么它们可以继续前进。如果一个棋子进入的格子已经被其他棋子标注为占用,那么这个棋子就不能再移动。给出棋子的数量,已经每个棋子的移动方向和开始坐标,计算每个棋子可以移动的步数。如果一个棋子可以无限移动,就标注为“N/A”。

输入范例:input.txt

6
0 3 5
90 5 3
0 4 6
0 10 4
90 11 2
90 8 1

上面的输入范例里,第一行的数字6表示棋盘上总共有六个棋子。从第二行开始,每一行代表一个棋子的信息。第一个数字表示当前棋子移动方向(0 为向东,90为向北),后面两个数字表示该棋子在棋盘上的(x, y) 坐标。

输出范例:output.txt

5
3
N/A
N/A
2
5

Python Solution

USACO Summary - Bronze Problem # 5