编程介的小学生 2017-08-13 11:59 采纳率: 20.5%
浏览 679
已采纳

Constructing Roads

Description

In the days of yore, Han was a prosperous kingdom. But at the turn of the century, hard times fell upon the kingdom. A plague swept through the land, and barbarians galloped in from the north, burning farms, destroying roads, and pillaging villages. All that remained were a few isolated strongholds scattered throughout the land. It has now been nearly a decade since the last wave of barbarians stormed through, and the land breathes a sigh of relief. People are becoming revitalized with the hope that they can once again transform the kingdom back into its former glory.

Since all the roads were destroyed, the strongholds were left in isolation, so the first order of business was to build a network of roads connecting all the strongholds. Each stronghold thought it would be a reasonable plan to start by building a road to the closest stronghold near it. If there were two strongholds of equal distance, the stronghold whose name comes before the other in the dictionary would be chosen. Each stronghold builds at its own rate, measured in feet/hour. Because they wished to finish as soon as possible, construction happened 24 hours a day, continuously advancing the construction site (the end of the road) towards the destination. Of course, construction on a road would stop if the road ran into another road or a city. At the beginning of the New Year, there was a big celebration, and all the strongholds began construction at the same time.

Little did the people of Han know that the barbarians had again infiltrated their kingdom and were carefully observing the progress of the roads. The barbarians were curious about the progress of the roads. In particular, they wanted answers to two type of questions.

After exactly t hours since construction began on the New Year, what is the absolute minimum length of additional roads that still need to be built in order to connect all cities? These additional roads are allowed to join two cities, two construction sites, or a city and a construction site.
What is the fewest number of hours that must elapse since the New Year before the minimum length of additional roads that still need to be built is at most l?
Write a program to answer these questions given Han’s construction plan.

Input

There will be several test cases, each representing a possible scenario for Han. The first line of each test case will contain a positive integer number N, the number of strongholds (1 ≤ N ≤ 2 000). Each of the subsequent N lines will contain a description of a stronghold: a name consisting of letters ‘ a’ … ‘z’, the x and y coordinates of the position of the stronghold (in feet), and the construction rate (in feet/hour). The next lines will contain questions. The first integer on the line is either 1 or 2, representing the type of question. For type 1 questions, the next number is t, the time (in hours) in question. For type 2 questions, the next number is l, the length (in feet) in question. The questions will be terminated by a line with 0.

The input data is terminated by a line that contains one zero, and should not be processed.

Output

For each test case, output the answers to each question, formatted as in the sample output. If for question 2, at no point in time will there be only l feet of construction left, then print NEVER. All numeric answers should be printed to as many decimal places as you feel necessary. To get credit for the problem, however, your answer must be within 0.01 of our answer.

Sample Input

4
portland 0 0 3
seattle 0 10 2
newyork 20 6 1
boston 20 0 1
1 0
1 2.0
1 3.0
2 29
2 1.0
0
2
bree -10 -10 1
buckland 10 10 2
1 5
0
0
Sample Output

Kingdom 1
36.000 feet left at time 0.000
22.000 feet left at time 2.000
20.000 feet left at time 3.000
1.000 hours before 29.000 feet left
NEVER

Kingdom 2
13.284 feet left at time 5.000

End

  • 写回答

1条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)