시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|

5 초 | 256 MB | 49 | 12 | 12 | 27.273% |

The International Commission for Perfect Cars (ICPC) has constructed a city scale test course for advanced driver assistance systems. Your company, namely the Automotive Control Machines (ACM), is appointed by ICPC to make test runs on the course.

The test course consists of streets, each running straight either east-west or north-south. No streets of the test course have dead ends, that is, at each end of a street, it meets another one. There are no grade separated streets either, and so if a pair of orthogonal streets run through the same geographical location, they always meet at a crossing or a junction, where a car can turn from one to the other. No U-turns are allowed on the test course and a car never moves outside of the streets.

Oops! You have just received an error report telling that the GPS (Global Positioning System) unit of a car running on the test course was broken and the driver got lost. Fortunately, however, the odometer and the electronic compass of the car are still alive.

You are requested to write a program to estimate the current location of the car from available information. You have the car’s location just before its GPS unit was broken. Also, you can remotely measure the running distance and the direction of the car once every time unit. The measured direction of the car is one of north, east, south, and west. If you measure the direction of the car while it is making a turn, the measurement result can be the direction either before or after the turn. You can assume that the width of each street is zero.

The car’s direction when the GPS unit was broken is not known. You should consider every possible direction consistent with the street on which the car was running at that time.

The input consists of a single test case. The first line contains four integers n, x_{0}, y_{0}, t, which are the number of streets (4 ≤ n ≤ 50), x- and y-coordinates of the car at time zero, when the GPS unit was broken, and the current time (1 ≤ t ≤ 100), respectively. (x_{0}, y_{0}) is of course on some street. This is followed by n lines, each containing four integers x_{s}, y_{s}, x_{e}, y_{e} describing a street from (x_{s}, y_{s}) to (x_{e}, y_{e}) where (x_{s}, y_{s}) ≠ (x_{e}, y_{e}). Since each street runs either east-west or north-south, x_{s} = x_{e} or y_{s} = y_{e} is also satisfied. You can assume that no two parallel streets overlap or meet. In this coordinate system, the x- and y-axes point east and north, respectively. Each input coordinate is non-negative and at most 50. Each of the remaining t lines contains an integer d_{i} (1 ≤ d_{i} ≤ 10), specifying the measured running distance from time i − 1 to i, and a letter c_{i}, denoting the measured direction of the car at time i and being either N for north, E for east, W for west, or S for south.

Output all the possible current locations of the car that are consistent with the measurements. If they are (x_{1}, y_{1}),(x_{2}, y_{2}), ... ,(x_{p}, y_{p}) in the lexicographic order, that is, x_{i} < x_{j} or x_{i} = x_{j} and y_{i} < y_{j} if 1 ≤ i < j ≤ p, output the following:

x_{1}y_{1}x_{2}y_{2}. . . x_{p}y_{p}

Each output line should consist of two integers separated by a space.

You can assume that at least one location on a street is consistent with the measurements.

4 2 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 2 1 9 N

1 1 2 2

6 0 0 2 0 0 2 0 0 1 2 1 0 2 2 2 0 0 0 2 1 0 1 2 2 0 2 2 2 E 7 N

0 1 1 0 1 2 2 1

7 10 0 1 5 0 10 0 8 5 15 5 5 10 15 10 5 0 5 10 8 5 8 10 10 0 10 10 15 5 15 10 10 N

5 5 8 8 10 10 15 5

ACM-ICPC > Regionals > Asia > Japan > Asia Regional Contest 2014 in Tokyo E번