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

建议使用的浏览器:

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

3184:Finicky Grazers

题目描述
Farmer John's N (1 <= N <= 10,000) cows (conveniently numbered 1..N) graze in a straight line in their pasture whose length is L+1 (N <= L <= 100,000) meters. Every morning, they place themselves at various unique integer locations along that line. FJ has observed that the cows produce more milk when the distance to the other grazing cows is maximized.

Always the enterprising farmer, FJ wants to maximize the distance between each and every pair of neighboring cows by moving the cows to the right or left, but always with integer inter-cow spacing and never changing their order on the line. He spends 1 minute to move a cow 1 meter. When he's finished, he knows that the distances between every adjacent pair of cows will be one of two integers: D or D+1.

Help FJ to calculate minimum time he needs to arrange the positions of the cows.
输入解释
Line 1: Two space-separated integers, N and L

Lines 2..N+1: Line i+1 describes cow i with a single integer (range 0..L) representing the position of a cow; 0 is the left-most position. The list is sorted by position with the smallest position value first.
输出解释
Line 1: A single line with minimum time FJ needs to arrange the positions of the cows.
输入样例
5 10
0
1
4
9
10
输出样例
3
提示
Explanation of the sample:

The cows are arranged like this at the start:
1 2 - - 3 - - - - 4 5
The cows end up arranged like this:
1 - 2 - 3 - - 4 - - 5
Cow #2 moves from position 1 to position 2 (1 meter). Cow #4 moves from position 9 to position 7 (2 meters). Other cows don't move. Moving times are 1+2=3, which is the final answer.

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3184

最后修改于 2020-10-29T06:55:11+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536