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

建议使用的浏览器:

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

5550:Game Rooms

题目描述
Your company has just constructed a new skyscraper, but you just noticed a terrible problem: there is only space to put one game room on each floor! The game rooms have not been furnished yet, so you can still decide which ones should be for table tennis and which ones should be for pool. There must be at least one game room of each type in the building.

Luckily, you know who will work where in this building (everyone has picked out offices). You know that there will be $T_{i}$ table tennis players and $P_{i}$ pool players on each floor. Our goal is to minimize the sum of distances for each employee to their nearest game room. The distance is the difference in floor numbers: 0 if an employee is on the same floor as a game room of their desired type, 1 if the nearest game room of the desired type is exactly one floor above or below the employee, and so on.
输入解释
The first line of the input gives the number of test cases, $T(1≤T≤100)$. $T$ test cases follow. Each test case begins with one line with an integer $N(2≤N≤4000)$, the number of floors in the building. $N$ lines follow, each consists of 2 integers, $T_{i}$ and $P_{i}(1≤T_{i},P_{i}≤10^{9})$, the number of table tennis and pool players on the $i_{th}$ floor. The lines are given in increasing order of floor number, starting with floor 1 and going upward.
输出解释
For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the minimal sum of distances.
输入样例
1
2
10 5
4 3
输出样例
Case #1: 9
提示
In the first case, you can build a table tennis game room on the first floor and a pool game room on the second floor. 
In this case, the 5 pool players on the first floor will need to go one floor up, and the 4 table tennis players on the second floor will need to go one floor down. So the total distance is 9.
来自杭电HDUOJ的附加信息
Recommend wange2014

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

源链接: HDU-5550

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

共提交 0

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