Problem F
Cars
The cars are already good at staying inside the lines and turning. However, they are not very good at detecting other moving vehicles. Fortunately, the government of Sweden is so enthusiastic about self-driving cars that they have banned all other forms of transportation in Stockholm, including human-driven cars, biking, and walking. If you can just detect whether two cars will collide you will be able to build a safe system.
You know that all cities consist of only north-south and east-west oriented streets in a perfect grid, and all cars are perfect rectangular prisms. When detecting collisions you only need to worry about cars traveling at a constant speed without turning.
Input
The first line of input contains an integer $1 \le t \le 10^4$, the duration in seconds of the trajectory of the two cars. Then follow the description of the trajectory of two cars.
A trajectory consists of a line containing a character $d$ and five integers $x$, $y$, $s$, $w$ and $l$. The starting position of the car is $(x,y)$ ($0 \le x, y \le 10^4$) and its direction is $d$ which is either N (positive $y$ direction), S (negative $y$ direction), W (negative $x$ direction) or E (positive $x$ direction). The car is travelling at a speed of $1 \le s \le 10^4$ units per second, is $1 \le w \le 10^4$ units wide, and $1 \le l \le 10^4$ units long.
Cars start out centred on their starting coordinates and do not initially overlap in a nonzero area.
Output
For each line of input, output a line “crash” if the two cars will crash or “safe” if they will not crash. If two cars overlap in an area of size zero (only on an edge or corner) they do not crash.
Sample Input 1 | Sample Output 1 |
---|---|
5 E 0 0 2 1 2 S 3 2 1 1 3 |
crash |
Sample Input 2 | Sample Output 2 |
---|---|
1 E 0 0 1 1 1 N 0 2 1 1 1 |
safe |
Sample Input 3 | Sample Output 3 |
---|---|
2 N 0 0 7 3 1 S 3 20 12 4 1 |
crash |
Sample Input 4 | Sample Output 4 |
---|---|
1 N 0 0 7 3 1 S 3 20 12 4 1 |
safe |