P3133 [USACO16JAN] Radio Contact G 无线电通话
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_{0 , 0} = 0\)
后记
考试时 \(dis\) 打错了,差点就寄了。
P3133 [USACO16JAN] Radio Contact G 无线电通话的更多相关文章
- 洛谷 P3133 [USACO16JAN]Radio Contact G
题目传送门 解题思路: f[i][j]表示FJ走了i步,Bessie走了j步的最小消耗值.方程比较好推. 横纵坐标要搞清楚,因为这东西WA了半小时. AC代码: #include<iostrea ...
- 洛谷 P3133 [USACO16JAN]无线电联系Radio Contact
P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the ...
- 「BZOJ4510」「Usaco2016 Jan」Radio Contact 解题报告
无线电联系 Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed t ...
- P3133 [USACO16JAN]无线电联系Radio Contact
题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! ...
- [USACO16JAN]Angry Cows G 解题报告
一图流 参考代码: #include<bits/stdc++.h> #define ll long long #define db double #define filein(a) fre ...
- 越狱Season 1-Episode 7: Riots, Drills and the Devil: Part 2
Season 1, Episode 7: Riots, Drills and the Devil: Part 2 -Pope: Belick, get those guys in line guy: ...
- VCF文件导入导出
参考资料 通讯录导入导出vcf格式文件方法可参考: https://qiaodahai.com/android-iphone-mobile-phones-contacts-import-and-exp ...
- [SinGuLaRiTy] 2017-07-21 综合性测试
[SinGuLaRiTy-1028] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 对于所有题目:Time Limit: 1s | Memo ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BlackArch-Tools
BlackArch-Tools 简介 安装在ArchLinux之上添加存储库从blackarch存储库安装工具替代安装方法BlackArch Linux Complete Tools List 简介 ...
随机推荐
- pysimplegui之列表布局
重点 1通过循环生成一行 2通过循环生成一列 3[]这个代表一行 4需要大量重复布局的时候可以使用 生成的布局(如果你有> 5个重复元素/行,一定要阅读) 本节讨论了 5 种生成布局的特定技术. ...
- 9.springSecurity整合OAuth2结合Jwt实现单点登录
1.总结:昨天主要是继续完善OAuth2配合将问题完成单点登录,昨天也应证了一个认证服务,两个客户端服务在登陆一次后可以访问两个客户端的页面,也算是完成了单点登录 2.具体实现 首先是使用java ...
- Java设计模式 —— 享元模式
14 享元模式 14.1 享元模式概述 Flyweight Pattern: 运用共享技术有效地支持大量细粒度对象的复用. 当系统中存在大量相同或相似的对象时,它通过共享技术实现相同或相似的细粒度对象 ...
- Unity快手上手【熟悉unity编辑器,C#脚本控制组件一些属性之类的】
Unity学习参考文档和开发工具 unity的官网文档:https://docs.unity3d.com/cn/current/Manual/ScriptingSection.html ■ 学习方式: ...
- JUC(四)多线程锁
目录 多线程锁 Synchronized锁的八种情况 公平锁和非公平锁 可重入锁 synchronized Lock 死锁 检查死锁 多线程锁 Synchronized锁的八种情况 以一个手机类为例, ...
- c++基本数据结构
基本数据结构: 一.线性表 1.顺序结构 线性表可以用普通的一维数组存储. 你可以让线性表可以完成以下操作(代码实现很简单,这里不再赘述): 返回元素个数. 判断线性表是否为空. 得到位置为p的元素. ...
- DevOps、SRE、平台工程的区别
DevOps.SRE和平台工程的概念在不同时期出现,并由不同的个人和组织开发. DevOps作为一个概念是由Patrick Debois和Andrew Shafer在2009年的敏捷会议上提出的.他们 ...
- 第138篇:了解HTTP协议(TCP/IP协议,DNS域名解析,浏览器缓存)
好家伙,发现自己的网络知识十分匮乏,赶紧补一下 这里先举个我生活中的例子 欸,作业不会写了,上网搜一下 用edge浏览器上bing必应搜一下(百度广告太多了,真不想用百度举例子) 假设这是我们 ...
- 用Aspose-Java免费实现 PDF、Word、Excel、Word互相转换并将转换过得文件上传OSS,返回转换后的文件路径
嘿嘿嘿.嘿嘿,俺又回来了! github代码地址 https://github.com/Tom-shushu/work-study 接口文档有道云 https://note.youdao.com/s/ ...
- GPT4free安装部署教程 - 白嫖GPT
前言 为啥之前一直没有更新GPT相关的内容,因为个人觉得如果每次都需要使用付费使用API的话,那这个工具还是很难在个人手上被运用起来,多测试几次关键字和清洗数据,API的费用对个人来说都太高昂了 直到 ...