题目描述

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: 复制

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

  1. 28
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define inf 2147483647
  5. const ll INF = 0x3f3f3f3f3f3f3f3fll;
  6. #define ri register int
  7. template <class T> inline T min(T a, T b, T c)
  8. {
  9. return min(min(a, b), c);
  10. }
  11. template <class T> inline T max(T a, T b, T c)
  12. {
  13. return max(max(a, b), c);
  14. }
  15. template <class T> inline T min(T a, T b, T c, T d)
  16. {
  17. return min(min(a, b), min(c, d));
  18. }
  19. template <class T> inline T max(T a, T b, T c, T d)
  20. {
  21. return max(max(a, b), max(c, d));
  22. }
  23. #define pi acos(-1)
  24. #define me(x, y) memset(x, y, sizeof(x));
  25. #define For(i, a, b) for (int i = a; i <= b; i++)
  26. #define FFor(i, a, b) for (int i = a; i >= b; i--)
  27. #define mp make_pair
  28. #define pb push_back
  29. const int maxn = ;
  30. // name*******************************
  31. int n,m;
  32. struct pos
  33. {
  34. int x,y;
  35. } a[],b[];
  36. int f[][];
  37. int ax,ay,bx,by;
  38. char s1[],s2[];
  39. // function******************************
  40. int dis(int i,int j)
  41. {
  42. 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);
  43. }
  44. //***************************************
  45. int main()
  46. {
  47. cin>>n>>m;
  48. cin>>ax>>ay>>bx>>by;
  49. a[].x=ax;
  50. a[].y=ay;
  51. b[].x=bx;
  52. b[].y=by;
  53. scanf("%s",s1+);
  54. scanf("%s",s2+);
  55. char c;
  56. For(i,,n)
  57. {
  58. c=s1[i];
  59. if(c=='N')
  60. {
  61. a[i].x=a[i-].x;
  62. a[i].y=a[i-].y+;
  63. }
  64. if(c=='S')
  65. {
  66. a[i].x=a[i-].x;
  67. a[i].y=a[i-].y-;
  68. }
  69. if(c=='E')
  70. {
  71. a[i].x=a[i-].x+;
  72. a[i].y=a[i-].y;
  73. }
  74. if(c=='W')
  75. {
  76. a[i].x=a[i-].x-;
  77. a[i].y=a[i-].y;
  78. }
  79. }
  80. For(i,,m)
  81. {
  82. c=s2[i];
  83. if(c=='N')
  84. {
  85. b[i].x=b[i-].x;
  86. b[i].y=b[i-].y+;
  87. }
  88. if(c=='S')
  89. {
  90. b[i].x=b[i-].x;
  91. b[i].y=b[i-].y-;
  92. }
  93. if(c=='E')
  94. {
  95. b[i].x=b[i-].x+;
  96. b[i].y=b[i-].y;
  97. }
  98. if(c=='W')
  99. {
  100. b[i].x=b[i-].x-;
  101. b[i].y=b[i-].y;
  102. }
  103. }
  104. me(f,);
  105. f[][]=;
  106. for(int i=; i<=n; i++)
  107. for(int j=; j<=m; j++)
  108. {
  109. if(i>=)
  110. f[i][j]=min(f[i][j],f[i-][j]+dis(i,j));
  111. if(j>=)
  112. f[i][j]=min(f[i][j],f[i][j-]+dis(i,j));
  113. if(i>=&&j>=)
  114. f[i][j]=min(f[i][j],f[i-][j-]+dis(i,j));
  115. }
  116.  
  117. cout<<f[n][m];
  118.  
  119. return ;
  120. }

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. Javascript全选,反选,全不选的实现代码

    使用js实现全选.反选.全不选. 代码如下: <html> <head> <script type="text/javascript"> fun ...

  2. 记录在window平台安装python的第三库(py,whl)

    在下载python的第三库文件的时候,有些库文件有exe的发行版,但是有些第三库并没有找到针对于window的可执行文件安装包即exe文件,而只有源代码文件即py文件,和whl文件. 下面记录一下在w ...

  3. Spring Hibernate JPA 联表查询 复杂查询

    今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的? 是.如果hibernate认为jpa的注解够用,就直接用.否则会弄一个自己的出来作为补充. 2)jpa和hibern ...

  4. Nginx的文件夹的别名设计&drupal简洁url

    参考:nginx 官方drupal 配置 - Drupal | NGINX 环境:ubuntu14,Nginx1.12, MariaDB5.5.56,PHP7.1.7 需求:1.不同的网站,不要用文件 ...

  5. Python 底层原理知识

    1.Python是如何进行内存管理的? 答:从三个方面来说,一对象的引用计数机制,二垃圾回收机制,三内存池机制 一.对象的引用计数机制 Python内部使用引用计数,来保持追踪内存中的对象,所有对象都 ...

  6. CentOS7系列--10.1CentOS7中的GNOME桌面环境

    CentOS7中的桌面环境 1. 安装GNOME桌面环境 1.1. 列出所有安装套件 [root@appclient ~]# yum groups list Loaded plugins: faste ...

  7. CentOS7系列--5.2CentOS7中配置和管理Docker

    CentOS7配置和管理Docker Docker是操作系统级别的虚拟化工具,它能自动化布署在容器中的应用 1. 安装Docker 1.1. 安装Docker相关软件 [root@server1 ~] ...

  8. linux 根据进程名杀死进程 -kill进程名

    前两天一个老师给我出了一个linux操作上的问题,现在知道进程名怎样杀死这个进程.或许很多人都会和我一样说用 #pkill 进程名 或是 #killall 进程名 的确这个两个命令都能做到这些,而且我 ...

  9. 2017 先知创新大会:有 ZHI 而来

    先知创新大会( XIANZHI INNOVATION CONFERENCE ) 是聚焦安全行业创新的行业盛事, 旨在推动安全技术的进步和发展. 先知大会的主题是“极致·眼界·创新” 极致:追求技术的极 ...

  10. 计算机二进制表示、cpu架构(x86_64)、cpu频率、核心、主板

    计算机二进制表示 色彩二进制表示: 红色 255,0,0绿色 0,255,0蓝色 0,0,255 文字二进制表示:A 65a 97 cpu架构 cpu架构有精简指令集和复杂指令集两种精简指令集cpu有 ...