ZOJ Problem Set - 1488

本文介绍了一个基于游戏《Uncharted Waters II》中导航系统的算法问题。玩家需找到从起点到目标港口的最短路径,路径需经过预设路径,并且尽可能早地到达。文章提供了输入输出样例及限制条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Navigation

Time Limit: 2 Seconds      Memory Limit: 65536 KB

There is a computer game which had been quite popular in China about 7 years ago named "Uncharted Waters II". This game has several versions on different platforms and the plot of this game is mainly about a young captain's voyage in the 16th century. There is a useful command in gameplay - devolve. With this command, you can only specify a port and your assistant will automatically guide you there via the shortest path.


(Screenshots for Uncharted Waters on SNES/SFC with emulator ZSNES)

As the topology is quite complicated, finding the shortest path between every two points seemed to be an impossible task at that time with only 486 computers. Actually, the game adopted a special method to get an approximation: There're some pre-set paths between the ports, and whenever you used the devolve command, your assistant first leads your ship to one of the shortest paths as quick as possible and then get to the target port along some preset paths.

One day, your assistant has retired and now you have to write a program to help yourself. Let's first suppose that the surface of the Earth is a plane(It was believed so at that time, wasn't it?), thus all ports can be represented by two coordinates x and y. All the pre-set paths are straight lines connecting two ports.

Now, given the coordinates of all ports and the ports that each pre-set path connects, you are to calculate the shortest paths between given pairs of initial position and a target port. Your result should satisfy:

1. It is (one of) the path(s) that reaches the pre-set paths as early as possible.

2. Under condition 1, it's (one of) the path(s) that reaches the target port as early as possible.


Input

The input contains several test cases. The first line of each case has 3 integers, N (1 <= N <= 50), M and L. N is the number of ports, M is the number of preset paths, L is the number of pairs of initial position and target port.

The following N lines each contains a name consists of no more than 15 letters followed by two real numbers representing the coordinates of that port.

The next M lines each contain the names of the 2 ports that path connects.

The last L lines each contain two real numbers as the coordinates of the initial position and a name as the target port. Input is terminated with a case of N = M = L = 0 which should not be proceeded.

You may assume:

1.Any two ports are connected via several preset paths.

2.No 2 preset paths interact except at ports.

3.All coordinated are between 0 and 1000 inclusively.


Output

For every pair of initial positon and a target port, output the length of the shortest path between them on a line of it's own. Rounded to 2 decimal places. Output a blank line after each case.


Sample Input

2 1 3
Hangzhou 1 1
Shanghai 3 1.5
Hangzhou Shanghai
0 0 Hangzhou
3 1 Hangzhou
0 0 Shanghai
4 4 2
LostTemple 1 1
TheHunters 2 3
NeoJungleStory 4 5
Rivalry 5 1
LostTemple TheHunters
TheHunters NeoJungleStory
NeoJungleStory Rivalry
Rivalry LostTemple
0 0 NeoJungleStory
3 0 NeoJungleStory
0 0 0


Sample Output

1.41
2.43
3.48

6.48
7.12

The two pictures above explain the two samples.


解题报告:

写了好久没写出来,有时间再想想,脑袋要炸了抓狂

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值