作者:ACShiryu
时间:2011-7-28
原题:http://poj.org/problem?id=2253
Frogger
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 13595 Accepted: 4521
Description
Freddy Frog is sitting _disibledevent=>Input
The input will contain _disibledevent=> Output
For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last _disibledevent=>Sample Input
2 0 0 3 4 3 17 4 19 4 18 5 0
Sample Output
Scenario #1 Frog Distance = 5.000 Scenario #2 Frog Distance = 1.414
题目大意,有两只青蛙,分别在两个石头上,青蛙A想要到青蛙B那儿去,他可以直接跳到B的石头上,也可以跳到其他石头上,再从其他石头跳到B那儿,求青蛙从A到B的所有路径中最小的Frog Distance,我们定义Frog Distance为从A到B的一条路径中所跳的最大距离,例如,如果从A到B某条路径跳的距离是2,5,6,4,则Frog Distance就是6,题目输入的第一行代表石头的个数,当个数为0时结束程序,接着有n行,其中第2,3行分别代表A,B青蛙的坐标,其他n-2行分别代表空的石头的坐标,输出一个小数(保留三位),具体格式参见样例,注意没输出一个答案还要再空一行。
题目数据1很明显为5.000
对于数据2青蛙有两种方案
方案1:1-2则经过距离为2.000故此时Frog Distance=2.000
方案2:1-3-2 则经过距离分别是1.414 1.414 故此时Frog Distance=1.414
故所求的最小的Frog Distance=1.414
这道题和POJ1797比较类似,那个是求最大生成树的最小权,这个是求最小生成树的最大权,哪题是用Kruskal+并查集做的,比较麻烦,则此从网上搜了小Prim算法,果然比较方面,开始时从图中取出点0(数组从0开始),入集合,然后搜索集合外的点到集合的距离,找出距离最小的点,入集合,重复该步骤,直到点1也进入了集合,则此时的权值就是所求的值。
刚开始输出没注意,WA了一次,这还是要提醒我们要小心注意题目的输入输出,别遗漏,确保万无一失才能交;
参考代码:
1 #include
最新评论