#C2674. Robot Collision Simulation
Robot Collision Simulation
Robot Collision Simulation
You are given n robots positioned on an infinite 2D grid with initial coordinates and a facing direction. The possible directions are: \(N\) (north), \(E\) (east), \(S\) (south), and \(W\) (west). Each robot then follows a series of commands. Each command specifies which robot (1-indexed) to move and the number of steps to move in its current facing direction.
The robots move simultaneously in a sequential order of commands, updating their positions. If, after any move, a robot lands on a cell that is already occupied by another robot, a collision occurs. Your task is to simulate the moves and determine whether any collision happens. Print "Yes" if a collision occurs; otherwise, print "No".
Note: Once a collision is detected during the simulation, no further commands need to be executed.
inputFormat
The input is given from the standard input (stdin) and is formatted as follows:
n x1 y1 d1 x2 y2 d2 ... (n lines in total)</p>m r1 s1 r2 s2 ... (m lines in total)
where:
- \(n\) is the number of robots.
- Each of the next \(n\) lines describes a robot's initial position and its facing direction \(d\) (one of N, E, S, W).
- \(m\) is the number of commands.
- Each of the next \(m\) lines contains two integers: the robot index (1-indexed) and the number of steps to move in the robot's facing direction.
outputFormat
Output a single line to the standard output (stdout) containing either "Yes" if any collision occurs during the simulation, or "No" if no collision takes place.
Note: Output must match exactly, including case.
## sample4
1 1 N
2 2 E
0 2 S
2 3 W
3
1 2
2 1
3 1
No
</p>