题意:求点1到点2的路径中,权值最大的那条边,其最小值是多少。

分析:最大值最小化。可以将迪杰斯特拉模板中的松弛操作加以修改,在O(n^2)的时间内解决该问题。其中需要注意的是,dist[i]指的是:走到点i的路径上,权值最大的边权。当每次找到最小的dist[u]之后,松弛操作是:对于点v,若max(d[u],G[u][v])>d[v],那么将d[v]跟新为max(d[u],G[u][v])。也就是说通过u的路径上最大的边权值如果小于的dist[v],显然dist[v]可以变得更小。

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>#
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const int maxn =2e2+;
const int maxM = <<;
#define INF 0x3f3f3f3f struct Node{
int x,y;
}point[maxn]; double G[maxn][maxn];
double d[maxn];
bool vis[maxn]; inline double dist(Node & a,Node &b) {return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));} void dij(int s,int n) {
memset(vis,,sizeof(vis));
for (int i = ; i <= n; i++)
d[i] = G[][i];
d[s] = ;
vis[s]= true;
for (int i = ; i <= n; i++){
int p = -;
double minn = INF;
for (int j = ; j <= n; j++){
if (!vis[j] && d[j] < minn){
minn = d[j];
p = j;
}
}
if (p == -) break;
vis[p] = true;
for (int j = ; j <= n; j++) {
if (!vis[j] && max(G[p][j],d[p]) < d[j]){ //寻求更小的路
d[j] = max(G[p][j],d[p]);
}
}
}
} int main()
{
int T=, N,u,v,x,y,tmp;
while(scanf("%d",&N)==,N){
for(int i =;i<=N;++i){
scanf("%d%d",&point[i].x,&point[i].y);
}
for(int i=;i<=N;++i){
G[i][i]=;
for(int j=i+;j<=N;++j){
G[i][j] = G[j][i] = dist(point[i],point[j]);
}
}
dij(,N);
printf("Scenario #%d\n",T++);
printf("Frog Distance = %.3f\n",d[]);
printf("\n");
}
return ;
}

POJ 2253 Frogger (Dijkstra变型)的更多相关文章

  1. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

  2. POJ 2253 - Frogger - [dijkstra求最短路]

    Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...

  3. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  4. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  5. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  6. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  7. poj 2253 Frogger (dijkstra最短路)

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

  8. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  9. POJ 2253 Frogger

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

  10. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

随机推荐

  1. 当input被选中时候获取改input的多个属性值

    <input name="selectTicket" class="selectTic" data-property="${couponDeta ...

  2. 如何给RecyclerView加上滚动条--现在就教你

    时隔许久,我又要更博了,含蓄的话不多说了,今天我们的主题是这个RecyclerView.至于为什么要加个scrollBar?因为我的业务需求是需要一个实现成这样的, 效果图:(可能看起来比较粗糙,但功 ...

  3. Sql Server根据表名生成查询的存储过程(查询条件可选)

    static void Main(string[] args) { string 表名 = "water_emstime"; string sql = "exec Get ...

  4. android手机有多个摄像头,打开其中一个

    方法: private Camera openFrontFacingCameraGingerbread() { int cameraCount = 0; Camera cam = null; Came ...

  5. MathType与Origin是怎么兼容的

    MathType作为一款常用的公式编辑器,可以与很多的软件兼容使用.Origin虽然是一款专业绘图与数据分析软件,但是在使用过程中也是可以用到MathType.它可以帮助Origin给图表加上标签,或 ...

  6. Bellman-Ford算法(有向图)

    #include <iostream> #include <cstring> #include <cstdio> #define MAX 100 #define I ...

  7. PowerDesigner使用教程3

    from:http://www.cnblogs.com/langtianya/archive/2013/03/08/2949118.html PowerDesigner是一款功能非常强大的建模工具软件 ...

  8. awk向脚本传递參数(二)

    命令行參数的一个重要限制是它们在BEGIN过程中是不可用的. 也就是说,直到首行输入完毕以后它们才可用.为什么?这是一个easy混乱的部分.从命令行传递的參数就好像文件名称一样被处理.赋值操作知道这个 ...

  9. Java Something

    Java静态代码检查工具 FindBugs FindBugs is a defect detection tool for Java that uses static analysis to look ...

  10. 使用 Visual Studio 2015 编译 QT 工程

    简单进行一下几步就可以了 1.下载源代码 qt-everywhere-opensource-src-5.6.0-alpha.7z .解压到 D:\ToolKits\5.6.0\src 目录下2.网站 ...