A898 | Radio Contact--Gold
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to
help him find it! They both fan out and search the farm along different paths,
but stay in contact via radio so they can keep in touch with each-other.
Unfortunately, the batteries in their radios are running low, so they want to
plan their movements so as to conserve power, by trying to stay always within
a short distance apart.
Farmer John starts at location ($f_x, f_y$) and plans to follow a path
consisting of $N$ steps, each of which is either 'N' (north), 'E' (east), 'S'
(south), or 'W' west. Bessie starts at location ($b_x, b_y$) and follows a
similar path consisting of $M$ steps. Both paths may share points in common.
At each time step, Farmer John can either stay put at his current location, or
take one step forward along his path, in whichever direction happens to be
next (assuming he has not yet reached the final location in his path). Bessie
can make a similar choice. At each time step (excluding the first step where
they start at their initial locations), their radios consume energy equal to
the square of the distance between them.
Please help FJ and Bessie plan a joint movement strategy that will minimize
the total amount of energy consumed up to and including the final step where
both of them first reach the final locations on their respective paths.
help him find it! They both fan out and search the farm along different paths,
but stay in contact via radio so they can keep in touch with each-other.
Unfortunately, the batteries in their radios are running low, so they want to
plan their movements so as to conserve power, by trying to stay always within
a short distance apart.
Farmer John starts at location ($f_x, f_y$) and plans to follow a path
consisting of $N$ steps, each of which is either 'N' (north), 'E' (east), 'S'
(south), or 'W' west. Bessie starts at location ($b_x, b_y$) and follows a
similar path consisting of $M$ steps. Both paths may share points in common.
At each time step, Farmer John can either stay put at his current location, or
take one step forward along his path, in whichever direction happens to be
next (assuming he has not yet reached the final location in his path). Bessie
can make a similar choice. At each time step (excluding the first step where
they start at their initial locations), their radios consume energy equal to
the square of the distance between them.
Please help FJ and Bessie plan a joint movement strategy that will minimize
the total amount of energy consumed up to and including the final step where
both of them first reach the final locations on their respective paths.
输入格式
The first line of input contains $N$ and $M$ ($1 \leq N, M \leq 1000$). The
second line contains integers $f_x$ and $f_y$, and the third line contains
$b_x$ and $b_y$ ($0 \leq f_x, f_y, b_x, b_y \leq 1000$). The next line
contains a string of length $N$ describing FJ's path, and the final line
contains a string of length $M$ describing Bessie's path.
It is guranteed that Farmer John and Bessie's coordinates are always in the
range ($0 \leq x,y \leq 1000$) throughout their journey. Note that East points
in the positive x direction and North points in the positive y direction.
second line contains integers $f_x$ and $f_y$, and the third line contains
$b_x$ and $b_y$ ($0 \leq f_x, f_y, b_x, b_y \leq 1000$). The next line
contains a string of length $N$ describing FJ's path, and the final line
contains a string of length $M$ describing Bessie's path.
It is guranteed that Farmer John and Bessie's coordinates are always in the
range ($0 \leq x,y \leq 1000$) throughout their journey. Note that East points
in the positive x direction and North points in the positive y direction.
输出格式
Output a single integer specifying the minimum energy FJ and Bessie can use
during their travels.
during their travels.
输入输出样例
输入 #1
2 7 3 0 5 0 NN NWWWWWN
输出 #1
28
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted