POJ 2253 Frogger (Dijkstra变型)
题意:求点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变型)的更多相关文章
- poj 2253 Frogger dijkstra算法实现
点击打开链接 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21653 Accepted: 7042 D ...
- POJ 2253 - Frogger - [dijkstra求最短路]
Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...
- 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 ...
- 最短路(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最短路)
题目链接: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
题目链接: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多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
随机推荐
- MPAndroidChart -- LimitLine的坑
好久没有写博客了,最近比较忙,项目中使用了MPAndroidChart,初次使用也比较蠢,很多API都得一个一个查,但有些时候当你想应该有这个API的时候他却没有,就比如今天的主角LimitLine ...
- AWT从概念产生到完成实现只用了一个月
这种糟糕的设计选择使得那些拥护Java“一次编写,到处运行 (write once, run anywhere)”信条的程序员们过得并不舒畅,因为AWT并不能保证他们的应用在各种平台上表现得有多相似. ...
- 嵌入式开发之davinci--- MSB和LSB
简介: MSB是Most Significant Bit的缩写,最高有效位.在二进制数中,MSB是最高加权位.与十进制数字中最左边的一位类似.通常,MSB位于二进制数的最左侧,LSB位于二进制数的最右 ...
- Sql Server根据表名生成查询的存储过程(查询条件可选)
static void Main(string[] args) { string 表名 = "water_emstime"; string sql = "exec Get ...
- PatternSyntaxException:Syntax error in regexp pattern
Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1: ...
- python bottle学习(一)快速入门
from bottle import (run, route, get, post, put, delete) # bottle中添加路由的两种方法 # 第一种,使用route装饰器,需要指定meth ...
- 使用HTML5构建iOS原生APP(2)
本文转载至 http://ju.outofmemory.cn/entry/18807 有时候我们在内嵌的webview中希望点击一个链接之后,触发iOS原生事件,而不是webview内页面跳转(因为w ...
- ios在数字键盘左下角添加“完成”按钮的实现原理
本文转载至 http://www.itnose.net/detail/6145865.html 最近要在系统弹出的数字键盘上的左下角额外添加一个自定制的完成按钮,于是研究了一下系统自带键盘添加自定制按 ...
- script跨域之360搜索
思考: 布局: 1,flex元素上下左右居中,内部元素横向排列: div{ /* 100vh = viewport height*/ display: flex; justify-content: c ...
- Windows窗口的层次关系(转)
今天看到这篇文章,觉得蛮有用的,我之前也对这个不大了解,特转载此处. 转载地址:http://www.51testing.com/html/200804/n80848.html 在Window 的图形 ...