题目描述

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_yfx​,fy​ ) and plans to follow a path consisting of NN steps, each of which is either 'N' (north), 'E' (east), 'S' (south), or 'W' west. Bessie starts at location (b_x, b_ybx​,by​ ) and follows a similar path consisting of MM 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 NN and MM (1 \leq N, M \leq 10001≤N,M≤1000 ). The

second line contains integers f_xfx​ and f_yfy​ , and the third line contains b_xbx​

and b_yby​ (0 \leq f_x, f_y, b_x, b_y \leq 10000≤fx​,fy​,bx​,by​≤1000 ). The next line contains a

string of length NN describing FJ's path, and the final line contains a string

of length MM describing Bessie's path.

It is guranteed that Farmer John and Bessie's coordinates are always in the

range (0 \leq x,y \leq 10000≤x,y≤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: 复制

2 7
3 0
5 0
NN
NWWWWWN
输出样例#1: 复制

28
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
const int maxn = ;
// name*******************************
int n,m;
struct pos
{
int x,y;
} a[],b[];
int f[][];
int ax,ay,bx,by;
char s1[],s2[];
// function******************************
int dis(int i,int j)
{
return (a[i].x-b[j].x)*(a[i].x-b[j].x)+(a[i].y-b[j].y)*(a[i].y-b[j].y);
}
//***************************************
int main()
{
cin>>n>>m;
cin>>ax>>ay>>bx>>by;
a[].x=ax;
a[].y=ay;
b[].x=bx;
b[].y=by;
scanf("%s",s1+);
scanf("%s",s2+);
char c;
For(i,,n)
{
c=s1[i];
if(c=='N')
{
a[i].x=a[i-].x;
a[i].y=a[i-].y+;
}
if(c=='S')
{
a[i].x=a[i-].x;
a[i].y=a[i-].y-;
}
if(c=='E')
{
a[i].x=a[i-].x+;
a[i].y=a[i-].y;
}
if(c=='W')
{
a[i].x=a[i-].x-;
a[i].y=a[i-].y;
}
}
For(i,,m)
{
c=s2[i];
if(c=='N')
{
b[i].x=b[i-].x;
b[i].y=b[i-].y+;
}
if(c=='S')
{
b[i].x=b[i-].x;
b[i].y=b[i-].y-;
}
if(c=='E')
{
b[i].x=b[i-].x+;
b[i].y=b[i-].y;
}
if(c=='W')
{
b[i].x=b[i-].x-;
b[i].y=b[i-].y;
}
}
me(f,);
f[][]=;
for(int i=; i<=n; i++)
for(int j=; j<=m; j++)
{
if(i>=)
f[i][j]=min(f[i][j],f[i-][j]+dis(i,j));
if(j>=)
f[i][j]=min(f[i][j],f[i][j-]+dis(i,j));
if(i>=&&j>=)
f[i][j]=min(f[i][j],f[i-][j-]+dis(i,j));
} cout<<f[n][m]; return ;
}

P3133 [USACO16JAN]无线电联系Radio Contact的更多相关文章

  1. 洛谷 P3133 [USACO16JAN]无线电联系Radio Contact

    P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the ...

  2. 「BZOJ4510」「Usaco2016 Jan」Radio Contact 解题报告

    无线电联系 Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed t ...

  3. 洛谷 P3133 [USACO16JAN]Radio Contact G

    题目传送门 解题思路: f[i][j]表示FJ走了i步,Bessie走了j步的最小消耗值.方程比较好推. 横纵坐标要搞清楚,因为这东西WA了半小时. AC代码: #include<iostrea ...

  4. APM和PIX飞控日志分析入门贴

    我们在飞行中,经常会碰到各种各样的问题,经常有模友很纳闷,为什么我的飞机会这样那样的问题,为什么我的飞机会炸机,各种问题得不到答案是一件非常不爽的问题,在APM和PIX飞控中,都有记录我们整个飞行过程 ...

  5. USACO 2016 January Contest, Gold解题报告

    1.Angry Cows http://www.usaco.org/index.php?page=viewproblem2&cpid=597 dp题+vector数组运用 将从左向右与从右向左 ...

  6. VCF文件导入导出

    参考资料 通讯录导入导出vcf格式文件方法可参考: https://qiaodahai.com/android-iphone-mobile-phones-contacts-import-and-exp ...

  7. Android app ADB命令

    * 查看设备 adb devices ps这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显示 若有多台安卓设备,可以通过在adb后面加上 -s <设备id&g ...

  8. [SinGuLaRiTy] 2017-07-21 综合性测试

    [SinGuLaRiTy-1028] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 对于所有题目:Time Limit: 1s | Memo ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. bzoj1061 NOI2018 志愿者招募——solution

    Description 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难 题:为即将启动的奥运新项目招募一批短期志愿者.经过估算,这个项目需要N 天才能 ...

  2. 记ASP.NET 使用 X509Certificate2 出现的一系列问题

    在做微信支付退款的时候,由于需要使用到p12证书,结果就遇到一系列的坑.这里做个记录方便以后查阅. 原先加载证书的代码: X509Certificate2 cert = new X509Certifi ...

  3. 关于Datastage资料库的一点小发现

    这里的资料库,指的是Datastage Metadata层,在Datastage7.5以后,需要在安装Datastage时安装一个数据库用于存放用户数据. 昨天领导要求安装Datastage集群/高可 ...

  4. 专访阿里资深研发工程师窦贤明:PG与商业数据库差距并不明显

    窦贤明认为, 支持类型.功能和语法丰富,性能优良   9月24日,窦贤明将参加在北京举办的线下活动,并做主题为<Greenplum分片案例分析>的分享.值此,他分享了PG.工作上的一些经历 ...

  5. Android 获取全局Context的技巧

    回想这么久以来我们所学的内容,你会发现有很多地方都需要用到Context,弹出Toast的时候需要.启动活动的时候需要.发送广播的时候需要.操作数据库的时候需要.使用通知的时候需要等等等等.或许目前你 ...

  6. Eclipse 校验取消

    eclipse Multiple annotations found at this line错误,eclipse开发过程中,一些XML配置文件会报错,但是这些其实不是错,飘红的原因是因为eclips ...

  7. 【Java】生成UUID

    import java.util.UUID; public class MainProcess { public static void main(String[] args) { UUID uuid ...

  8. makedown 软件

    windows上的新手使用makedownpad 很适合的 下载之后你需要激活makedownpad MarkdownPad 2 Pro 注册码(邮箱+许可密钥) 邮箱 Soar360@live.co ...

  9. Python入门-模块1(模块导入与time模块)

    ---恢复内容开始--- 模块 一.模块分类: 模块分为三种: 1.内置模块:Python自带的标准模块(可使用help('modules’)查看Python自带模块列表) 2.第三方开源模块:可以通 ...

  10. "字符串"经过strip 之后还是字符串, 而"字符串"经过split 分开后,就变成了一个列表["x","xx","xxx"]

    "字符串"经过strip 之后还是字符串, 而"字符串"经过split 分开后,就变成了一个列表["x","xx",&q ...