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 简介 ...
随机推荐
- [网络/Linux]处理安全报告/安全漏洞的一般流程与思路
对近期工作中所经历的4次处理第三方网络安全公司的安全报告及其安全漏洞的经验做一点小结. 1 流程 Stage1 阅读/整理/分类:安全漏洞报告的安全漏洞 (目的:快速了解漏洞规模和分布) Stage2 ...
- sorted、返回函数、匿名函数、装饰器、偏函数
1.sorted()排序方法,它可已经一个列表按照升序排序,也可以按照反序排序 1)如果要进行反序排序时,需要在函数里面设置reverse = True 2)sorted是一个高阶函数,它接受函数作为 ...
- 四月十五号java基础知识
1.今天下午做了一个题感受很深,自己做题没有思路或者有点思路死磕也没有搞清楚,看起来很简单的问题,在我手里很难 做咯许久还是室友帮忙解决的,后面重新打一遍还是出问题,找他解决的,问了问他我自己的问题, ...
- 【Voyage】GDOI 2023 旅游记 || ECHO.
\(\color{#FFFFFF}{那是什么样的旅途呢}\) \(\color{#FFFFFF}{真的会害怕很多东西呢.想想害怕的其实不止这样一件事,便产生了"其实都一样没关系的,都应该踏过 ...
- 如何使用Redis做缓存
如何使用Redis做缓存 我们都知道Redis作为NoSql数据库的代表之一,通常会用来作为缓存使用.也是我在工作中通常使用的缓存之一. 1.我们什么时候缓存需要用到Redis? 我认为,缓存可以分为 ...
- Vuex刷新页面数据会丢失吗?咋解决的?
1.问题描述:页面刷新的时候vuex里的数据会重新初始化,导致数据丢失.因为vuex里的数据是保存在运行内存中的,当页面刷新时,页面会重新加载vue实例,vuex里面的数据就会被重新赋值. 2.解决思 ...
- RDIF.vNext全新低代码快速开发框架平台发布
1.平台介绍 RDIF.vNext,全新低代码快速开发集成框架平台,给用户和开发者最佳的.Net框架平台方案,为企业快速构建跨平台.企业级的应用提供强大支持. RDIF.vNext的前身是RDIFra ...
- React课堂笔记1
一.概要 React是用于构建用户界面的MVVM框架. React拥有较高的性能,代码逻辑非常简单,越来越多的人已开始关注和使用它.认为它可能是将来Web开发的主流工具之一. 官网:https://z ...
- ubutn在线服务器python Package安装到离线服务器
1.在线服务器导出requirement.txt pip freeze > requirement.txt 该文件生成完毕后,需要做些修改,去掉不需要的库,否则下载的时候会出错. 2.下载whl ...
- C# 从0到实战 变量的定义与使用
变量的定义 变量本质是一种内存的占位符,使得我们可以轻松操作计算机.C#的变量声明格式是: 类型 名称 = 值: 1 //.... 2 3 int val = 0; //定义并赋值 4 5 Conso ...