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

建议使用的浏览器:

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

1153:SAFE

题目描述
Mirko has decided to rob mini-safe owned by his son so that he could take away some football stickers which are missing in his big sticker collection.
Lock on the safe consists of N equal discs, each of them being divided in 10,000,000 equal segments numbered from 1 to 10,000,000 clockwise. In the begining, segments on discs having the same number are placed one above (beneath) the other. Discs are layed one on the other such that the segments are overlaping and each disc is missing exactly one segment that is called hole.
In order to unlock the lock, all holes must be one above (beneath) the other.In one second, Mirko can turn one disc in one direction (clockwise or counterclockwise) for one segment.
Write a program which will find the minimal time that Mirko needs to open the safe.
输入解释
The first line of the input contains an integer N, 2 <= N <= 100,000, the number of discs.
The next N lines contain data describing the initial positions of the holes on each disc.
The (i + 1)-th line contains an integer Pi, 1 <= Pi <= 10000000, the initial position of the hole on the i-th disc.
输出解释
The first and only line of the output should contain the minimal time (in seconds).
Note: take care of the size of that number.
输入样例
4
9999999
7
16
9999995
输出样例
29

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

源链接: POJ-1153

最后修改于 2020-10-29T05:54:12+00:00 由爬虫自动更新

共提交 2

通过率 0.0%
时间上限 内存上限
1000 10000