首页 > 其他分享 >P3133 [USACO16JAN] Radio Contact G 无线电通话

P3133 [USACO16JAN] Radio Contact G 无线电通话

时间:2023-07-03 20:56:43浏览次数:41  
标签:P3133 leq 样例 their Contact Radio Bessie FJ USACO16JAN

P3133 [USACO16JAN] Radio Contact G 无线电通话

目录

题目传送门

[USACO16JAN] Radio Contact G

题目描述

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.

FJ失去了他最喜欢的牛铃,而Bessie已经同意帮助他找到它!他们用不同的路径搜索农场,通过无线电保持联系。不幸的是,无线电中的电池电量不足,所以他们设法尽可能保持两者位置的距离最小,以节省电量。

FJ从位置(fx,fy)开始,并计划遵循由N步骤组成的路径,每个步骤都是“N”(北),“E”(东),“S”(南),或“W”(西)。Bessie从位置(bx,by)开始,并遵循由M步骤组成的类似路径。两个路径可以经过相同的点。在每个时间段,FJ可以保持在他现在的位置,或沿着他的道路前进一步,无论哪个方向恰好在下一个(假设他还没有到达他的路径的最后位置)。Bessie可以做出类似的选择。在每个时间步(不包括从初始位置开始的第一步),他们的无线电消耗的能量等于它们之间距离的平方。

请帮助FJ和Bessie计划行动策略,最大限度地减少消耗的能量总量。总量包括最终步骤,这时两者首先到达各自路径上的最终位置。

输入格式

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.

第一行输入N和M(1≤N,M≤1000)。

第二行输入整数fx和fy,第三行输入bx和by(0≤fx,fy,bx,≤1000)。下一行包含一个长度为N的字符串描述FJ的路径,最后一行包含一个字符串的长度M描述Bessie的路径。

数据满足(0≤x,y≤1000)。注意,东方向为正X方向,北方向为正Y方向。

输出格式

Output a single integer specifying the minimum energy FJ and Bessie can use

during their travels.

输出一个整数,表示最小能量。

样例 #1

样例输入 #1

2 7
3 0
5 0
NN
NWWWWWN

样例输出 #1

28

提示

感谢@ prcups 改进翻译

思路

先分别求出农夫和奶牛没走一步到达的点

设 \(dp_{i , j}\) 当农夫走了 \(i\) 步,奶牛走了 \(j\) 步后的最小花费

那么

\[dp_{i , j} = min (dp_{i - 1 , j} , min (dp _{i , j - 1 } , dp _{i - 1 , j - 1 })) +dis(i , j) \]

注意判断越界条件,\(dp_{0 , 0} = 0\)

后记

考试时 \(dis\) 打错了,差点就寄了。

标签:P3133,leq,样例,their,Contact,Radio,Bessie,FJ,USACO16JAN
From: https://www.cnblogs.com/2020fengziyang/p/17524005.html

相关文章

  • 前端实现radio+其它自定义输入选项
    后端数据库设计:1.类型字段  2.用户输入的其它信息记录字段 前端:<el-form-itemlabel="性能要求类型">     <el-radio-groupv-model="form.performanceRequirementType">      <el-radio       v-for="dictinperformanceRequire......
  • 终端运行roscore时,报错:Unable to contact my own server at...
    问题现象:问题原因:以上问题是由于ROS环境变量ROS_MASTER_URI设置错误导致的,重新设置该变量即可。解决方法:打开~/.bashrc文件,添加或修改环境变量ROS_HOSTNAME和ROS_MASTER,即改为:exportROS_HOSTNAME=localhostexportROS_MASTER_URI=http://localhost:11311修改并保存~/.......
  • Codeforces Round #375 (Div. 2)-C. Polycarp at the Radio
    原题链接C.PolycarpattheRadiotimelimitpertestmemorylimitpertestinputoutputa1, a2, ..., an,where ai isaband,whichperformsthe i-thsong.Polycarplikesbandswiththenumbersfrom 1 to ......
  • jquery获取radio选中的值
    radio 1.获取选中值$('input:radio:checked').val();$("input[type='radio']:checked").val();$("input[name='rd']:checked").val(); 参考:https://www.jb51.net/article/154831.htm ......
  • 前端基于 radio 增强单选框组件
    前端基于radio增强单选框组件, 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=12977效果图如下:    #####使用方法```使用方法<!--radioData:单选数据curIndex:当前选择序列@change:单选事件--><ccRadioView:radioData="i......
  • el-radio默认水平排列变垂直排列
    el-radio默认是水平排列的,在项目里面是竖直排列,我用块级元素div嵌套不起作用,最后的解决方法是:1:deep(.el-radio-group){2display:block;3}45:deep(.el-radio){6display:block;7} ......
  • element的el-radio垂直排列
    element里面的el-radio是水平排列的,在项目里面需要竖直排列的效果,我给每个el-radio都加了块级作用域没生效,最后的解决方法是://单选框:deep(.el-radio){display:block;} ......
  • element Cascader级联选择器 选择任意一级选项及点文字即可选中(去掉radio按钮)
    首先放出官网效果:项目需求:将示例的点击radio和点击文字功能结合在一起。可以选择任意一级的内容,直接点击文字即可选中,同时如果有下一级就展示,去掉radio标签。实现思路:通过css将radio标签做成文字框一样大小并且透明覆盖在整个文字上方,点击文字的时候其实是在点击radio标签css......
  • wpf 自定义 RadioButton.
    <StyleTargetType="RadioButton"x:Key="nav"><SetterProperty="Template"><Setter.Value><ControlTemplateTargetType="RadioButton">......
  • 0x7A51EF8C (ucrtbased.dll)处(位于 contact.exe 中)引发的异常
    c语言在使用vs提供的scanf_s时  <p>charname[60];<br/>scanf_s("%s",name,60);<br/>printf("%s",name);<br/>return0;</p>debug结果为:0x7A51EF8C(ucrtbased.dll)处(位于contact.exe中)引发的异常:0xC0000005:写......