POJ 2253 Frogger(SPFA运用)

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 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,求青蛙a在能跳到青蛙b的所有路径上最长边的最小值。
思路:对于给定的坐标我们可以将之转换成一个距离矩阵,距离由两点间距离公式求出来,之后用一遍最短路就OK啦(不过在松弛的时候是求最长边的最小值)

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<iomanip>
 5 #include<vector>
 6 #include<queue>
 7 #include<cmath>
 8 
 9 using namespace std;
10 const int INF = 900000000;
11 struct point {
12     int x, y;
13 }e[220];
14 int n, vis[220], f[220];
15 double mp[220][220], dis[220];
16 void SPFA(int s)
17 {
18     for (int i = 1; i <= n; i++) {
19         dis[i] = INF;
20         vis[i] = 0; f[i] = 0;
21     }
22     queue<int>Q;
23     dis[s] = 0; vis[s] = 1; f[s]++;
24     Q.push(s);
25     while (!Q.empty()) {
26         int t = Q.front(); Q.pop();
27         vis[t] = 0;
28         for (int i = 1; i <= n; i++) {
29             if (dis[i] > max(dis[t], mp[t][i])) {
30                 dis[i] = max(dis[t], mp[t][i]);
31                 if (!vis[i]) {
32                     vis[i] = 1;
33                     Q.push(i);
34                     if (++f[i] > n)return;
35                 }
36             }
37         }
38     }
39 }
40 int main()
41 {
42     ios::sync_with_stdio(false);
43     int T = 1;
44     while ((cin >> n)) {
45         if (n == 0)break;
46         for (int i = 1; i <= n; i++)cin >> e[i].x >> e[i].y;
47         if (n == 2) {
48             double dis = sqrt((e[1].x - e[2].x)*(e[1].x - e[2].x) + (e[1].y - e[2].y)*(e[1].y - e[2].y));
49             cout << "Scenario #" << T++ << endl;
50             cout << "Frog Distance = " << fixed << setprecision(3) << dis << endl << endl;
51             continue;
52         }
53         for (int i = 1; i <= n; i++)
54             for (int j = 1; j <= i; j++)//求出ij之间的距离转换成距离矩阵
55                 mp[i][j] = mp[j][i] = sqrt((double)((e[i].x - e[j].x)*(e[i].x - e[j].x)) + (double)((e[i].y - e[j].y)*(e[i].y - e[j].y)));
56         SPFA(1);
57         cout << "Scenario #" << T++ << endl;
58         cout << "Frog Distance = " << fixed << setprecision(3) << dis[2] << endl << endl;//行末两个换行!!!!!
59     }
60 
61     return 0;
62 }

 

转载于:https://www.cnblogs.com/wangrunhu/p/9496702.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
疫情居家办公系统管理系统按照操作主体分为管理员和用户。管理员的功能包括办公设备管理、部门信息管理、字典管理、公告信息管理、请假信息管理、签到信息管理、留言管理、外出报备管理、薪资管理、用户管理、公司资料管理、管理员管理。用户的功能等。该系统采用了MySQL数据库,Java语言,Spring Boot框架等技术进行编程实现。 疫情居家办公系统管理系统可以提高疫情居家办公系统信息管理问题的解决效率,优化疫情居家办公系统信息处理流程,保证疫情居家办公系统信息数据的安全,它是一个非常可靠,非常安全的应用程序。 管理员权限操作的功能包括管理公告,管理疫情居家办公系统信息,包括外出报备管理,培训管理,签到管理,薪资管理等,可以管理公告。 外出报备管理界面,管理员在外出报备管理界面中可以对界面中显示,可以对外出报备信息的外出报备状态进行查看,可以添加新的外出报备信息等。签到管理界面,管理员在签到管理界面中查看签到种类信息,签到描述信息,新增签到信息等。公告管理界面,管理员在公告管理界面中新增公告,可以删除公告。公告类型管理界面,管理员在公告类型管理界面查看公告的工作状态,可以对公告的数据进行导出,可以添加新公告的信息,可以编辑公告信息,删除公告信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值