POJ 2253 Frogger floyd变形

曾经终败给现在 2022-06-10 05:55 241阅读 0赞

滴,集训第二十五天打卡。

最近又好热好热了呀…

POJ 2253 Frogger

Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists’ sunscreen, he wants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona’s stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog’s jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.

You are given the coordinates of Freddy’s stone, Fiona’s stone and all other stones in the lake. Your job is to compute the frog distance between Freddy’s and Fiona’s stone.

Input

The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy’s stone, stone #2 is Fiona’s stone, the other n-2 stones are unoccupied. There’s a blank line following each test case. Input is terminated by a value of zero (0) for n.

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 one.

Sample Input

  1. 2
  2. 0 0
  3. 3 4
  4. 3
  5. 17 4
  6. 19 4
  7. 18 5
  8. 0

Sample Output

  1. Scenario #1
  2. Frog Distance = 5.000
  3. Scenario #2
  4. Frog Distance = 1.414

题目大意:给定n个点的坐标,青蛙要从点1跳到点2,求最短路。

  1. #include <iostream>
  2. #include <string.h>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <algorithm>
  6. using namespace std;
  7. struct point
  8. {
  9. double x,y;
  10. }pp[210];
  11. double map[210][210],dis[210][210];
  12. int main()
  13. {
  14. int count=0,i,j,k,n;
  15. while(scanf("%d",&n),n)
  16. {
  17. for(i=1;i<=n;++i)
  18. scanf("%lf%lf",&pp[i].x,&pp[i].y);
  19. for(i=1;i<=n;i++)
  20. {
  21. for(j=1;j<=n;j++)
  22. {
  23. map[i][j]=sqrt((pp[j].x-pp[i].x)*(pp[j].x-pp[i].x)+(pp[j].y-pp[i].y)*(pp[j].y-pp[i].y));
  24. dis[i][j]=map[i][j];
  25. }
  26. }
  27. printf("Scenario #%d\nFrog Distance = ",++count);
  28. for(k=1;k<=n;k++)
  29. {
  30. for(i=1;i<=n;i++)
  31. {
  32. for(j=1;j<=n;j++)
  33. {
  34. if(dis[i][j]>max(dis[i][k],dis[k][j]))
  35. dis[i][j]=max(dis[i][k],dis[k][j]);
  36. }
  37. }
  38. }
  39. printf("%.3lf\n\n",dis[1][2]);
  40. }
  41. return 0;
  42. }

发表评论

表情:
评论列表 (有 0 条评论,241人围观)

还没有评论,来说两句吧...

相关阅读

    相关 POJ2253 Frogger(Floyd)

    题目描述:青蛙A要找青蛙B,路径任选,求所有可能路径中跳的最远的一步,它们之中的最小距离值。 输入要求,第一行为石头数,二三行为起点和终点位置,n-2行为其他石头结点。第一

    相关 poj 2253(区间DP)

    [原题][Link 1] 思路:求所有路径中最大跳跃距离的最小值, 很诡异的是输出答案如果用G++,.3lf%格式会出错,c++可以过 include<cstdio