TopCoder上一道600分滴题

问题大意是:一个无限大棋盘上有n个棋子,棋子每次可以上、下、左、右移动一格,求
使 k(0<k<=n)个棋子重叠在一格内,最少要移动几步。
分析了下有点类似点的聚类,考虑只能垂直的四个方向移动,所以定义点之间的距离
dis(a,b)=abs(a[x] - b[x]) + abs(a[y] - b[y]),剩下的就是求k个点到其中心的距离和最
小。但这看起来是穷举C(k,n)了。
  
  
原文如下:
Problem Statement
    
N checkers are placed on an infinitely large board. The i-th checker is in the cell  
at row x[i], column y[i]. There can be more than one checker in the same cell. A  
move consists of taking one checker and moving it one cell up, down, left or  
right.
Return a vector containing exactly N elements, where the i-th element (0-
based) is the minimum number of moves necessary to end up with at least i+1  
checkers in the same cell.
Definition
    
Class:
TheTower
Method:
count
Parameters:
vector , vector
Returns:
vector
Method signature:
vector count(vector x, vector y)
(be sure your method is public)
    
  
Constraints
-
x will contain between 1 and 50 elements, inclusive.
-
y will contain the same number of elements as x.
-
Each element of x will be between 1 and 1,000,000, inclusive.
-
Each element of y will be between 1 and 1,000,000, inclusive.
Examples
0)
  
    
{1, 2, 4, 9}
{1, 1, 1, 1}
Returns: {0, 1, 3, 10 }
Here is one possible way to get the minimal number of moves:
for 1 checker: do nothing
for 2 checkers: put the first two checkers at cell (1, 1)
for 3 checkers: put the first three checkers at cell (2, 1)
for 4 checkers: put all the checkers at cell (3, 1)
1)
  
    
{15, 15, 14, 16}
{14, 16, 15, 15}
Returns: {0, 2, 3, 4 }
Whenever we need to have more than one checker in a single cell, we can put  
them in cell (15, 15).
2) 
  
  
  

TopCoder上一道600分滴题
原文地址:https://www.cnblogs.com/liuzhuqing/p/7480615.html