POJ 2253 Frogger(SPFA运用)
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
Output
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啦(不过在松弛的时候是求最长边的最小值)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<vector>
#include<queue>
#include<cmath> using namespace std;
const int INF = ;
struct point {
int x, y;
}e[];
int n, vis[], f[];
double mp[][], dis[];
void SPFA(int s)
{
for (int i = ; i <= n; i++) {
dis[i] = INF;
vis[i] = ; f[i] = ;
}
queue<int>Q;
dis[s] = ; vis[s] = ; f[s]++;
Q.push(s);
while (!Q.empty()) {
int t = Q.front(); Q.pop();
vis[t] = ;
for (int i = ; i <= n; i++) {
if (dis[i] > max(dis[t], mp[t][i])) {
dis[i] = max(dis[t], mp[t][i]);
if (!vis[i]) {
vis[i] = ;
Q.push(i);
if (++f[i] > n)return;
}
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
int T = ;
while ((cin >> n)) {
if (n == )break;
for (int i = ; i <= n; i++)cin >> e[i].x >> e[i].y;
if (n == ) {
double dis = sqrt((e[].x - e[].x)*(e[].x - e[].x) + (e[].y - e[].y)*(e[].y - e[].y));
cout << "Scenario #" << T++ << endl;
cout << "Frog Distance = " << fixed << setprecision() << dis << endl << endl;
continue;
}
for (int i = ; i <= n; i++)
for (int j = ; j <= i; j++)//求出ij之间的距离转换成距离矩阵
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)));
SPFA();
cout << "Scenario #" << T++ << endl;
cout << "Frog Distance = " << fixed << setprecision() << dis[] << endl << endl;//行末两个换行!!!!!
} return ;
}
POJ 2253 Frogger(SPFA运用)的更多相关文章
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
随机推荐
- SQLServer —— 数据类型的转换
一.使用convert函数实现强制转换 例如我们现在有如下一张学员成绩表: 现在想查询学号等于100003的学员总成绩,并按照要求打印出来,我们可以这样实现: 结果报错,因为最后一句字符串不能和数值相 ...
- 基于TCP编程的socket
什么是TCP/IP.UDP? TCP/IP(Transmission Control Protocol/Internet Protocol)即传输控制协议/网间协议,是一个工业标准的协议集,它是为广域 ...
- 2019.11.12htmlhomework1
ex: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- Facebook POP 进阶指南
本文转自Kevin Blog Facebook 在发布了 Paper 之后,似乎还不满足于只是将其作为一个概念性产品,更进一步开源了其背后的动画引擎 POP,此举大有三年前发布的 iOS UI 框架 ...
- Java练习 SDUT-3268_飞花的糖果
飞花的糖果 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 一日,飞花壕大手一挥,买了N个的两两不相同糖果,他想要拿出M ...
- HDU_1005:Number Sequence
Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...
- Java面向对象----String对象的声明和创建
String a="abcd" 相等 String b="abcd" String a=new String("abcd") 不等于 ...
- nodeJs学习-02 fs模块(文件操作)
读文件: const fs = require('fs'); //读文件(异步) readFile(文件名,回调函数) fs.readFile('section03/testData/aaa.txt' ...
- oracle函数 DUMP(w[,x[,y[,z]]])
[功能]返回数据类型.字节长度和在内部的存储位置. [参数] w为各种类型的字符串(如字符型.数值型.日期型……) x为返回位置用什么方式表达,可为:8,10,16或17,分别表示:8/10/16进制 ...
- Python基础:27执行环境
一:可调用对象 可调用对象,是任何能通过函数操作符“()”来调用的对象.Python 有4 种可调用对象:函数,方法,类,以及一些类的实例. 1:函数 python 有 3 种不同类型的函数对象. a ...