menu ZJOJ
account_circle 请登录
home
首页
book
题目
apps
分类
play_circle_outline
状态
assessment
竞赛
assignment
作业
equalizer
排名
assignment_ind
登录
person_add
注册
1563: 东南西北
时间限制:1.000s
内存限制:128MB

题目描述

给出起点和终点的坐标,及接下来 lns="http://www.w3.org/1998/Math/MathML">T 个时刻的风向(东南西北),每个时刻可以选择顺风偏移 lns="http://www.w3.org/1998/Math/MathML">1 个单位或者停在原地。求到达终点的最少移动步数

坐标采用平面直角坐标系,lns="http://www.w3.org/1998/Math/MathML">x 轴正向为东,lns="http://www.w3.org/1998/Math/MathML">y 轴正向为北。

如果无法偏移至终点,输出 lns="http://www.w3.org/1998/Math/MathML">-1

输入格式

第一行两个正整数 lns="http://www.w3.org/1998/Math/MathML">x_1,y_1,表示小明所在位置。

第二行两个正整数 lns="http://www.w3.org/1998/Math/MathML">x_2,y_2,表示小明想去的位置。

第三行一个整数 lns="http://www.w3.org/1998/Math/MathML">T,表示 lns="http://www.w3.org/1998/Math/MathML">T 个时刻。

第四至第 lns="http://www.w3.org/1998/Math/MathML">N+3 行,每行一个字符,表示风向,即东(lns="http://www.w3.org/1998/Math/MathML">\verb!E!)南(lns="http://www.w3.org/1998/Math/MathML">\verb!S!)西(lns="http://www.w3.org/1998/Math/MathML">\verb!W!)北(lns="http://www.w3.org/1998/Math/MathML">\verb!N!)的英文单词的首字母。

输出格式

一行一个整数,表示最少移动步数。

样例输入 content_copy

1 1
2 2
5
E
N
W
W
N

样例输出 content_copy

2

提示/说明

样例解释

  • 样例 lns="http://www.w3.org/1998/Math/MathML">1:向东走一步,向北走一步。

数据范围

对于全部数据,lns="http://www.w3.org/1998/Math/MathML">1\le T\le 50

分类