Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 414 | Accepted: 146 |
Description
You are to write a program to, given the dimensions R and C of a grid, the coordinates x and y of a point P on one of the edges of the grid, and the direction (up, left), (down, left), (up, right), or (down, right) of the first line, help the professor to find out the number of minimal rectangles.
Input
The first line of each block, contains two positive integers R and C, which are the number of horizontal and vertical gridlines, respectively (2 <= R,C <= 1000). The coordinates of the starting point comes on the next line, as two positive integers y and x, (1 <= y <= R, 1 <= x <= C ); for the upper-left point of the grid, we have x = y = 1. The third line of each test case, contains a two-character code which is one of the following:
- "DR", the first move is in the down-right direction,
- "DL", the first move is in the down-left direction,
- "UL", the first move is in the up-left direction,
- "UR", the first move is in the up-right direction.
Output
Sample Input
2 4 5 2 1 DR 4 5 4 1 UR
Sample Output
1 3
Source
/*
Keep fighting.
計算幾何題,仔細思考不難發現,所有直線交點(轉折點除外,即反射點),所有當前
新生成的直線與其相鄰直線外所有直線交點的個數和即爲所求,所以在模擬過程中可以
存儲所有的直線當處理某一條直線時,只需遍歷所有已經生成的直線(其相鄰直線除外)
統計交點個數即可。終止條件的判斷用了個技巧,每個點都有1,2,3,4四個方向,如果
有哪個點的方向被重複或者到底矩形的四個頂點則訪問終止
*/