#P2689. 东南西北
东南西北
Description
Given the coordinates of the start and end points, and the wind direction (east, south, west, north) at each of the next time steps, you may either move unit with the wind or stay in place at each time step. Find the minimum number of moves needed to reach the destination.
The coordinate system is the Cartesian plane, where the positive -axis points east and the positive -axis points north.
If it is impossible to reach the destination, output .
Input Format
The first line contains two positive integers , representing Xiaoming’s current position.
The second line contains two positive integers , representing the position Xiaoming wants to reach.
The third line contains an integer , representing time steps.
From line to line , each line contains one character representing the wind direction, i.e., the first letter of the English words for east (), south (), west (), and north ().
Output Format
Output a single integer, the minimum number of moves.
1 1
2 2
5
E
N
W
W
N
2
1 1
2 2
1
W
-1
1 1
2 2
3
W
W
W
-1
Hint
Sample Explanation
- Sample : Move one step east, then one step north.
- Samples and : Impossible to reach.
Constraints
For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号