当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3597:BOMB

题目描述
Our space military base is under attack.The virus break into our computer,and destroy the CCS(Carrier Control System).Carrier is a kind of spaceship,which has the most powerful weapon.We have tried several times to find out the way to take control of them again.Unfortunately,at last we realized that our carriers are not belong to us anymore.We nosed out that our enemy who comes from Chars,a planet with many wise cultures living in,had embezzled the command of the carriers from us.Soon after,We recived a command from our SCO(space command office).It says we have to destroy all the uncontrollable carriers.
According to the information report we got from our spy organization,All the uncontrollable carriers are fly in a circle rail.To make a easier problem,we divide the circle into equal N(N<=100000000) parts and number it from 0 to N-1. We can consider that the length every part of rail is 1.In light of our report,there are M(M<=100000) carriers are uncontrollable.The number i uncontrollable carrier is at the middle of the number p[i](0<=p[i]<=N-1) rail.To destroy the carriers,we have M remote control bombs.The number I bombs is at the middle of the number q[i](0<=q[i]<=N-1) rail.We can let a bomb move to a carrier.When it move from number i rail to number i+1(or number i-1) rail it cost 1 energy(bombs in number N-1 rail can move to number 0 rail ,it also cost 1 energy;Remember bombs cannot leave the rail ) .The more energy we used when we move,The less damage we can make to the carriers.Clearly, We must spend the minimal energy to move all the bombs on to the carrier.One bombs can just destroy one carrier,even two carrier are at the same place.
We can imagine that carrier do not move.
输入解释
There are several test case.
For each test case: The first line contain 2 integers.N,M. Then followed 2*m lines,1..m line contain p[i],and m+1..2*m lines contain q[i];
输出解释
For each test case,print the minimal energy we have to spent to move all the bombs to destroy all the carriers.
输入样例
10 4
0
1
2
3
8
9
4
5
输出样例
8
来自杭电HDUOJ的附加信息
Author DingShuai
Recommend zhengfeng

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3597

最后修改于 2020-10-25T23:05:06+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 65536/32768K(Java/Others)