10 人解决,15 人已尝试。
10 份提交通过,共有 49 份提交。
6.4 EMB 奖励。
单点时限: 2.0 sec
内存限制: 256 MB
After scrimping and saving for years, Farmer John has decided to build a new barn. He wants the barn to be highly accessible, and he knows the coordinates of the grazing spots of all N (2 ≤ N ≤ 10,000 cows. Each grazing spot is at a point with integer coordinates (Xi, Yi) (-10,000 ≤ Xi ≤ 10,000; -10,000 ≤ Yi ≤ 10,000). The hungry cows never graze in spots that are horizontally or vertically adjacent.
The barn must be placed at integer coordinates and cannot be on any cow’s grazing spot. The inconvenience of the barn for any cow is given the Manhattan distance formula | X - Xi | + | Y - Yi|, where (X, Y) and (Xi, Yi) are the coordinates of the barn and the cow’s grazing spot, respectively. Where should the barn be constructed in order to minimize the sum of its inconvenience for all the cows?
Line 1: A single integer: N
Lines 2..N+1: Line i+1 contains two space-separated integers which are the grazing location (Xi, Yi) of cow i
Line 1: Two space-separated integers: the minimum inconvenience for the barn and the number of spots on which Farmer John can build the barn to achieve this minimum.
4 1 -3 0 1 -2 1 1 -1
10 4
10 人解决,15 人已尝试。
10 份提交通过,共有 49 份提交。
6.4 EMB 奖励。