题目链接:http://poj.org/problem?id=2253
Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 31114   Accepted: 10027

Description

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

2
0 0
3 43
17 4
19 4
18 50

Sample Output

Scenario #1
Frog Distance = 5.000Scenario #2
Frog Distance = 1.414

题意:
从起点到终点会有很多路径,每条路径上的边有一个最大值,求这些最大值中的最小值。
也就是更新的边要保持最大边。
Floyd
 1 #include <iostream>
 2 #include <cstdlib>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <queue>
 9 using namespace std;
10
11
12 #define INF 0x3f3f3f3f
13 #define N 300
14 struct node
15 {
16     int x, y;
17 };
18
19 double dist[N];
20 double G[N][N];
21 int vis[N], n;
22
23 void IN()
24 {
25     memset(vis, 0, sizeof(vis));
26
27     for(int i=1; i<=n; i++)
28     {
29         dist[i]=INF;
30         for(int j=1; j<=i; j++)
31             G[i][j]=G[j][i]=INF;
32     }
33 }
34
35 void Floyd()
36 {
37     for(int k=1; k<=n; k++)
38     {
39         for(int j=1; j<=n; j++)
40         {
41             for(int i=1; i<=n; i++)
42             {
43                 if(G[j][i] > max(G[j][k], G[k][i]))
44                 G[j][i] = max(G[j][k], G[k][i]);
45             }
46         }
47     }
48 }
49
50 int main()
51 {
52    int i, j, t=1;
53
54    while(scanf("%d", &n), n)
55    {
56        double  w;
57        node s[N];
58        memset(s, 0, sizeof(s));
59        IN();
60
61        for(i=1; i<=n; i++)
62            scanf("%d%d", &s[i].x, &s[i].y);
63
64        for(i=1; i<n; i++)
65        for(j=i+1; j<=n; j++)
66        {
67            w = sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)*1.0 + (s[i].y-s[j].y)*(s[i].y-s[j].y)*1.0);
68            G[i][j] = G[j][i]=min(G[i][j], w);
69        }
70
71        printf("Scenario #%d\n", t++);
72
73        Floyd();
74
75        printf("Frog Distance = %.3f\n\n", G[1][2]);
76
77    }
78     return 0;
79 }

dijkstra

 #include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<queue>using namespace std;#define INF 0xfffffff#define N 1100struct node{int x, y;}a[N];int n, vis[N];
double dist[N], G[N][N];void Dij()
{int i, j;for(i=1; i<=n; i++){dist[i] = G[1][i];vis[i] = 0;}vis[1] = 1;for(i=1; i<n; i++){int index=1;double Min=INF;for(j=1; j<=n; j++){if(!vis[j] && dist[j]<Min){Min = dist[j];index = j;}}if(index==1)continue;vis[index] = 1;for(j=1; j<=n; j++)if(!vis[j] && max(dist[index], G[index][j])<dist[j])dist[j] = max(dist[index], G[index][j]);}
}int main()
{int iCase = 1;while(scanf("%d", &n), n){int i, j;for(i=1; i<=n; i++)scanf("%d%d", &a[i].x, &a[i].y);for(i=1; i<=n; i++)for(j=1; j<=i; j++){double d = sqrt( (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) );G[i][j] = G[j][i] = d;}Dij();printf("Scenario #%d\n", iCase++);printf("Frog Distance = %.3f\n\n", dist[2]);}return 0;
}

prim

类似于最小生成树

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int INF = (1<<30)-1;
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define N 1100struct node
{int x, y;
}a[N];int n, m;
double dist[N], G[N][N];
int vis[N];double prim()
{int i, j;double ans = -1;for(i=1; i<=n; i++)dist[i] = G[1][i];dist[1] = 0;memset(vis, 0, sizeof(vis));vis[1] = 1;for(i=1; i<=n; i++){int index = 1;double Min = INF;for(j=1; j<=n; j++){if(!vis[j] && dist[j]<=Min){Min = dist[j];index = j;}}if(index==1) break;vis[index] = 1;ans = max(ans, Min);if(index==2) return ans;for(j=1; j<=n; j++){if(!vis[j] && dist[j]>G[index][j])dist[j] = G[index][j];}}return ans;
}int main()
{int  iCase=1;while(scanf("%d", &n), n){int i, j;memset(a, 0, sizeof(a));for(i=1; i<=n; i++)scanf("%d%d", &a[i].x, &a[i].y);for(i=1; i<=n; i++)for(j=1; j<=i; j++)G[i][j] = G[j][i] = sqrt( (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) );printf("Scenario #%d\n", iCase++);printf("Frog Distance = %.3f\n\n", prim());}return 0;
}

转载于:https://www.cnblogs.com/YY56/p/4658201.html

(最短路 Floyd diskstra prim)Frogger --POJ--2253相关推荐

  1. B - Frogger POJ - 2253

    B - Frogger POJ - 2253 题意: 从 1 号点出发,找每一条能够到达 2 号点的路径,每条路径的答案是该路径中相邻两点之间距离的最大值,求这些答案中的最小值. 思路: 感觉不是最短 ...

  2. POJ 3165 最短路 floyd

    POJ  3165  最短路 floyd http://poj.org/problem?id=3615 dp方程(f[i][j]>MAX(f[i][k],f[k][j])) f[i][j]=MA ...

  3. dijkstra算法_Python实现图的经典DFS、BFS、Dijkstra、Floyd、Prim、Kruskal算法

    讲在前面的话,图的算法太多,理论知识肯定一篇文章讲不完,关于理论知识大家可以参考教材Sedgewick的<算法>或reference的链接,本文主要还是想在一篇文章中记录六种算法的Pyth ...

  4. dfs时间复杂度_Python实现图的经典DFS、BFS、Dijkstra、Floyd、Prim、Kruskal算法

    讲在前面的话,图的算法太多,理论知识肯定一篇文章讲不完,关于理论知识大家可以参考教材Sedgewick的<算法>或reference的链接,本文主要还是想在一篇文章中记录六种算法的Pyth ...

  5. 【bzoj2324】[ZJOI2011]营救皮卡丘 最短路-Floyd+有上下界费用流

    原文地址:http://www.cnblogs.com/GXZlegend/p/6832504.html 题目描述 皮卡丘被火箭队用邪恶的计谋抢走了!这三个坏家伙还给小智留下了赤果果的挑衅!为了皮卡丘 ...

  6. HDU1869---(最短路+floyd)

    http://acm.hdu.edu.cn/showproblem.php?pid=1869 思路:最短路+floyd 分析: 1 题目是要求所有的数据能否满足"六度分离",那么我 ...

  7. POJ 2253 Frogger(最短路 Floyd)

    Frogger 大意: 给出两个青蛙的坐标和其他n-2个石头的坐标,任一两个坐标点间都是双向连通的.现在要求求出所有通路的最大距离,并把这些最大距离作比较,把最小的一个最大距离作为青蛙的最小跳远距离. ...

  8. POJ 2253 Frogger(最短路Floyd)题解

    题意:想给你公青蛙位置,再给你母青蛙位置,然后给你剩余位置,问你怎么走,公青蛙全力跳的的最远距离最小. 思路:这里不是求最短路径,而是要你找一条路,青蛙走这条路时,对他跳远要求最低.这个思想还是挺好迁 ...

  9. POJ 2253 Frogger(floyd dijkstra spfa)

    题目链接:http://poj.org/problem?id=2253 题目: 弗雷迪青蛙正坐在湖中央的一块石头上. 突然,他注意到正坐在另一块石头上的菲奥娜青蛙. 他打算去看望她,但由于水很脏,游客 ...

最新文章

  1. Pandas基础用法合集(中文官档)
  2. 用微信公众号做一个网页版商城
  3. 工业用微型计算机(28)-dos和bios功能调用(2)-int 21h
  4. kafka丢数据问题方案(转载+整理+汇总)
  5. IDEA——常用快捷键
  6. java channel源码_java nio ServerSocketChannel源码分析
  7. C# 调用c++ 实例
  8. 完了!Oracle 被虐!MySQL 登顶 Top1!原来这么多人都在用
  9. 52. 配置 Etag (13)
  10. 149.直线上最多的点数
  11. WS2811芯片 SM16703 SOP8 RGB流水幻彩灯LED驱动IC
  12. 奈奎斯特稳定性判据的步骤(含详细推导)
  13. 以太坊漫游指南:读懂以太坊发展路线图
  14. 【JDBC】操作数据库(CRUD)
  15. linux上如何把2个或者多个显示器合并为一个显示器
  16. 到了2017还在苦等房价下跌的人,你们可以醒醒了!
  17. 自然语言处理评测汇总(持续更新)
  18. 2021前端面试经典计算题总结。
  19. ui-bootstrap-tpls 中文 现在还不全的啊~,组件太多了,有空就更新
  20. Google 学术搜索增加电子邮件提醒功能

热门文章

  1. Mysql 解决emoji表情处理问题 - Incorrect string value: ‘\xF0\x9F\x92\x94‘ for column
  2. WP8多分辨率解决方案
  3. Jupyter-notebook安装问题及解决
  4. 【Selenium-WebDriver自学】出现的问题和解决方案(十七)
  5. 如何重置/删除chrome的输入突出显示/焦点边框? [重复]
  6. 如何在IntelliJ中永久启用行号?
  7. 如何删除尾随换行符?
  8. 电脑遇到蓝屏代码0x000007b问题如何解决
  9. 全向轮机器人左向直线运动分析
  10. vue中的防抖函数写法