POJ2253 Frogger

解题思路:floyed模板题(稍微变换一点),不解释,上代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 #define inf 0x3f3f3f3f
 7 const int maxn = 205;
 8 double w[maxn][maxn];
 9
10 struct node{
11     double x, y;
12 }p[maxn];
13
14 int main()
15 {
16     int n, kase = 1;
17     while(~scanf("%d", &n) && n)
18     {
19         for(int i = 1; i <= n; i++)
20         for(int j = i; j <= n; j++)
21         {
22             if(i == j) w[i][j] = 0;
23             else w[i][j] = w[j][i] = inf;
24         }
25
26         for(int i = 1; i <= n; i++)
27         scanf("%lf %lf", &p[i].x, &p[i].y);
28
29         for(int i = 1; i <= n; i++)
30         {
31             for(int j = i; j <= n; j++)
32             {
33                 double x2 = p[j].x - p[i].x;
34                 double y2 = p[j].y - p[i].y;
35
36                 w[i][j] = w[j][i] = sqrt(x2*x2 + y2*y2);
37             }
38         }
39
40         for(int i = 1; i <= n; i++)
41         {
42             for(int j = 1; j <= n; j++)
43             {
44                 for(int k = j; k <= n; k++)
45                 {
46                     if(w[j][i] <= w[j][k] && w[i][k] <= w[j][k])
47                     {
48                         w[j][k] = w[k][j] = max(w[j][i], w[i][k]);
49                     }
50                 }
51             }
52         }
53
54         printf("Scenario #%d\nFrog Distance = %.3lf\n\n", kase++, w[1][2]);
55     }
56     return 0;
57 }

时间: 2024-08-08 09:22:57

POJ2253 Frogger的相关文章

POJ2253 Frogger 【Floyd】

讲的是,一只雄青蛙要从一个石头到另外一个石头上去找某只雌青蛙,但是这两个石头隔得太远,青蛙跳不过去,所幸,湖面上还有很多其他石头,所以青蛙可以借助别的石头一步一步地跳向那只雌青蛙所在的石头.显然青蛙可能有多种路径,比如其中一条是 2,3,4,2,1 ,它跳了五次,数字代表每次跳的距离也就是路径上相邻两个石头之间的距离,那么这只青蛙的弹跳能力至少是4才能跳过去.在其他的路径中,可能要求青蛙的弹跳是5,是8,是1,是100,等等,这个问题求青蛙需要的最小弹跳能力.其实也就是个最大值中取最小的问题.

poj2253 Frogger(最短路变型或者最小生成树)

1 /* 2 题意:就是源点到终点有多条的路径,每一条路径中都有一段最大的距离! 3 求这些路径中最大距离的最小值! 4 5 Dijkstra, Floyd, spfa都是可以的!只不过是将松弛的条件变一下就行了! 6 7 想了一下,这道题用最小生成树做也可以啊,图总是连通的嘛!所以建一棵最小 8 生成树,然后dfs一下,从源点1,到终点2的路径上,查找边长最大的路径! 9 附上代码..... 10 */ 11 #include<iostream> 12 #include<cstdio&

POJ2253——Frogger(Floyd变形)

Frogger DescriptionFreddy 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 swimm

POJ2253 Frogger 【Dijkstra】

Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26417   Accepted: 8592 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,

POJ2253 Frogger —— 最短路变形

题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49409   Accepted: 15729 Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on a

poj2253 Frogger(Floyd)

题目链接 http://poj.org/problem?id=2253 题意 给出青蛙A,B和若干石头的坐标,现在青蛙A要跳到青蛙B所在的石头上,求出所有路径中最远那一跳的最小值. 思路 Floyd算法的变形,将求两点之间的最短路改成求两点之间最大边权的最小值即可. 代码 1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 #inclu

POJ-2253 Frogger dijsktra查找间隔最小的路径

题目链接:https://cn.vjudge.net/problem/POJ-2253 题意 一只Forg需要从节点1走到节点n 现要找一条各个间隔最小的路径 问间隔最小是多少 思路 用dijsktra就好 查找间隔最小的路径 注意浮点数的比较 代码 #include <cstdio> #include <vector> #include <queue> #include <cmath> using namespace std; const int maxn

poj图论解题报告索引

最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman-ford,spfa) poj1511 - Invitation Cards(单源来回最短路径,spfa邻接表) poj1797 - Heavy Transportation(最大边,最短路变形,dijkstra,spfa,bellman-ford) poj2240 - Arbitrage(汇率问题,

最短路径 专题总结

一.模板: 1.dijsktra算法(矩阵): 1 int n,cost[1005][1005],dis[1005],vis[1005],dp[1005]; 2 void dijkstra(int st) 3 { 4 memset(vis,0,sizeof(vis)); 5 for(int i = 1; i<=n; i++) 6 dis[i] = (i==st?0:INF); 7 8 for(int i = 1; i<=n; i++) 9 { 10 int k, minn = INF; 11