1072 Gas Station (30 分)
A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the houses are in its service range.
Now given the map of the city and several candidate locations for the gas station, you are supposed to give the best recommendation. If there are more than one solution, output the one with the smallest average distance to all the houses. If such a solution is still not unique, output the one with the smallest index number.
Input Specification:
Each input file contains one test case. For each case, the first line contains 4 positive integers: N (≤103), the total number of houses; M (≤10), the total number of the candidate locations for the gas stations; K (≤104), the number of roads connecting the houses and the gas stations; and D**S, the maximum service range of the gas station. It is hence assumed that all the houses are numbered from 1 to N, and all the candidate locations are numbered from G
1 to G
M.
Then K lines follow, each describes a road in the format
1 | P1 P2 Dist |
where P1
and P2
are the two ends of a road which can be either house numbers or gas station numbers, and Dist
is the integer length of the road.
Output Specification:
For each test case, print in the first line the index number of the best location. In the next line, print the minimum and the average distances between the solution and all the houses. The numbers in a line must be separated by a space and be accurate up to 1 decimal place. If the solution does not exist, simply output No Solution
.
Sample Input 1:
1 | 4 3 11 5 |
Sample Output 1:
1 | G1 |
Sample Input 2:
1 | 2 1 2 10 |
Sample Output 2:
1 | No Solution |
作者: CHEN, Yue
单位: 浙江大学
时间限制: 200 ms
内存限制: 64 MB
代码长度限制: 16 KB
题目大意
有一片居民区,现在要修建一个气站。气站有m个候选点,要求气站与最近房子距离最大。如果有多个选择,选与房子平均距离最小的。如果仍有多个,选择序号小的。
分析
实际上就是对m个候选点用dijkstra算法。关键在于给出的数据中,会有气站与房子,气站与气站的情况。因此得先判断输入的是房子还是气站。房子编号1-N,如果是气站,则在N之后编号。G1即为N+1,依次类推。
代码
我的代码最后一个测试点不过,不知道什么原因。后来照着https://www.liuchuo.net/archives/2376 修改,大概是数组初始化的问题。这里就不贴代码了。可以参考柳婼大佬的代码。