编程介的小学生 2017-08-10 13:55 采纳率: 20.5%
浏览 813
已采纳

Bus Terminals

Description

Yong-In city plans to build a bus network with N bus stops. Each bus stop is at a street corner. Yong-In is a modern city, so its map is a grid of square blocks of equal size. Two of these bus stops are to be selected as hubs H1 and H2. The hubs will be connected to each other by a direct bus line and each of the remaining N − 2 bus stops will be connected directly to either H1 or H2 (but not to both), but not to any other bus stop.

The distance between any two bus stops is the length of the shortest possible route following the streets. That is, if a bus stop is represented as (x, y) with x-coordinate x and y-coordinate y, then the distance between two bus stops (x1, y1) and (x2, y2) is . If bus stops A and B are connected to the same hub H1, then the length of the route from A to B is the sum of the distances from A to H1 and from H1 to B. If bus stops A and B are connected to different hubs, e.g., A to H1 and B to H2, then the length of the route from A to B is the sum of the distances from A to H1, from H1 to H2, and from H2 to B.

The planning authority of Yong-In city would like to make sure that every citizen can reach every point within the city as quickly as possible. Therefore, city planners want to choose two bus stops to be hubs in such a way that in the resulting bus network the length of the longest route between any two bus stops is as short as possible.

One choice P of two hubs and assignments of bus stops to those hubs is better than another choice Q if the length of the longest bus route is shorter in P than in Q. Your task is to write a program to compute the length of this longest route for the best choice P.
Input

Your program is to read from standard input. The first line contains one positive integer N, 2 <= N <= 500, the number of bus stops. Each of the remaining N lines contains the x-coordinate followed by the y-coordinate of a bus stop. The x- and y-coordinates are positive integers <= 5000. No two bus stops are at the same location.
Output

Your program is to write to standard output. The output contains one line with a single positive integer, the minimum length of the longest bus route for the input.
Sample Input

7
7 9
10 9
5 3
1 1
7 2
15 6
17 7
Sample Output

25

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-08-24 15:07
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算