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多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
随机推荐
- MonoTouch
本文为2012年4月19日Xamarin研讨会OLO在线咨询高级软件工程师Greg Shackles的一份的演讲资料. 本文为2012年4月19日Xamarin研讨会OLO在线咨询高级软件工程师Gre ...
- C++ STL标准模板库(vector)
//vector的使用 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> using na ...
- hdu 4284(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4284 思路:类似于poj3311:http://poj.org/problem?id=3311,首先f ...
- Django之前端模板继承
在使用Django进行web开发时,往往会构造一个基础框架模板即base.html,而后在其子模板中对它所包含站点公用部分和定义块进行重载. 首先创建一个base.html,源码为: <!DOC ...
- springside4
https://github.com/springside/springside4/wiki/Design Design 1. Web MVC Framwork: SpringMVC3.0 Restf ...
- SQL系统函数——系统信息
1.查看信息1.1.查看编号和名称select @@SERVERNAME--SQL SERVER服务器的连接字符串,如:computername\instancenameselect @@SERVIC ...
- 【BZOJ1264】[AHOI2006]基因匹配Match DP+树状数组
[BZOJ1264][AHOI2006]基因匹配Match Description 基因匹配(match) 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种碱基排列而 ...
- .then()
reference: http://www.html-js.com/article/Study-JavaScript-jQuery-Deferred-and-promise-every-day 1.5 ...
- Python SQLAlchemy基本操作和常用技巧(包含大量实例,非常好)
https://www.jb51.net/article/49789.htm 首先说下,由于最新的 0.8 版还是开发版本,因此我使用的是 0.79 版,API 也许会有些不同.因为我是搭配 MySQ ...
- Tornado实战
抽屉之Tornado实战(1)--分析与架构 抽屉之Tornado实战(2)--数据库表设计 抽屉之Tornado实战(3)--注册 抽屉之Tornado实战(4)--发帖及上传图片 抽屉之Torna ...