编程介的小学生 2019-12-31 21:56 采纳率: 20.5%
浏览 44

Settling Salesman Problem 是怎么写呢

Problem Description
After travelling around for years, Salesman John has decided to settle. He wants to build a new house close to his customers, so he doesn't have to travel as much any more. Luckily John knows the location of all of his customers.
All of the customers' locations are at (distinct) integer coordinates. John's new house should also be built on integer coordinates, which cannot be the same as any of the customers' locations. Since John lives in a large and crowded city, the travelling distance to any customer is the Manhattan distance: |x - xi| + |y - yi|, where (x, y) and (xi, yi) are the coordinates of the new house and a customer respectively.
What is the number of locations where John could settle, so the sum of the distance to all of his customers is as low as posible?

Input
On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case:

One line with an integer n (1 <= n <= 2 000): the number of customers John has.

n lines with two integers xi and yi (-1 000 000 000 <= xi, yi <= 1 000 000 000): the coordinates of the i-th customer.

Output
For each test case:

Two space-separated integers: the minimum summed distance to all customers, and the number of spots on which John can build his new house to achieve this minimum.

Sample Input
2
4
1 -3
0 1
-2 1
1 -1
2
-999888777 1000000000
1000000000 -987654321

Sample Output
10 4
3987543098 3975087573110998514

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
    • ¥15 钢筋实图交点识别,机器视觉代码
    • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
    • ¥50 400g qsfp 光模块iphy方案
    • ¥15 两块ADC0804用proteus仿真时,出现异常
    • ¥15 关于风控系统,如何去选择