POJ-2253 Frogger(最短路)
https://vjudge.net/problem/POJ-2253
题意
公青蛙想到母青蛙那里去,期间有许多石头,公青蛙可以通过这些石头跳过去。问至少要跳的最大距离,即所有路径上石头间的最大距离的最小值。
分析
这题是最短路的变形,最短路求的是路径总长的最小值,而此题是求通路中最长边的最小值。其实就是对最短路的定义不同: 一般的最短路为“每个边的权值之和”,这个题的最短路为 “各个边的权值的最大值”。注意格式输出,G++用%f。
#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
template <class T>
inline bool scan_d(T &ret){
char c;int sgn;
if(c=getchar(),c==EOF) return ;
while(c!='-'&&(c<''||c>'')) c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='') ret = ret*+(c-'');
ret*=sgn;
return ;
}
const int N = 1e6+;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = ;
int T; void testcase(){
printf("Case %d:",++T);
} const int MAXN = 5e5+ ;
const int MAXM = ;
const double eps = 1e-;
const double PI = acos(-1.0); struct point{
int x,y;
}node[MAXM]; double w[MAXM][MAXM],dis[MAXM];
int n;
int vis[MAXM]; double dist(point a,point b){
return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} void init(){
for(int i=;i<=n;i++) scanf("%d%d",&node[i].x,&node[i].y);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
w[i][j]=dist(node[i],node[j]);
}
void dijkstra(){
mset(vis,);
for(int i=;i<=n;i++) dis[i]=inf;
dis[]=;
for(int i=;i<=n;i++){
int pos,m=inf;
for(int j=;j<=n;j++){
if(!vis[j]&&dis[j]<m){
pos=j;
m=dis[j];
}
}
vis[pos]=;
for(int j=;j<=n;j++){
dis[j]=min(dis[j],max(dis[pos],w[pos][j]));
}
}
}
int main() { int t=;
while(~scanf("%d",&n)&&n){
init();
dijkstra();
if(t) puts("");
printf("Scenario #%d\nFrog Distance = %.3f\n", ++t, dis[]);
}
return ;
}
POJ-2253 Frogger(最短路)的更多相关文章
- POJ 2253 Frogger 最短路 难度:0
http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...
- poj 2253 Frogger(最短路 floyd)
题目:http://poj.org/problem?id=2253 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元 ...
- POJ 2253 Frogger -- 最短路变形
这题的坑点在POJ输出double不能用%.lf而要用%.f...真是神坑. 题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值. 算法:Dijkstra 题目每次选择权值最小的边进行延伸访 ...
- POJ 2253 Frogger (最短路)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28333 Accepted: 9208 Descript ...
- POJ 2253 Frogger ( 最短路变形 || 最小生成树 )
题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...
- 最短路(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 Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
随机推荐
- 深入浅出OAuth2.0授权
一.前言 说到OAuth,先来一段百度到的比较官方的解释: OAUTH协议为用户资源的授权提供了一个安全的.开放而又简易的标准.与以往的授权方式不同之处是OAUTH的授权不会使第三方触及到用户的帐号信 ...
- BLCR技术初探
BLCR技术到底是什么技术?我没空和你乱扯,自己去看该官方网站的介绍:http://crd.lbl.gov/groups-depts/ftg/projects/current-projects/BLC ...
- HTML 背景实例
71.HTML 背景实例好的背景使站点看上去特别棒.背景(Backgrounds)<body> 拥有两个配置背景的标签.背景可以是颜色或者图像.<body> 标签中的背景颜色( ...
- IT简历
对很多IT毕业生来说,写简历投简历是必不可少的.一个好的简历已是面试成功的一半. 简历的目的是为了引人注意,争取让HR主动联系你去面试,不可避免的在简历中掺杂着一些水分,但是能争取到面试机会,再与HR ...
- [SHELL]输入输出重定向与管道
一 . 输出重定向(将命令的输出重定向到文件): ls -al > test 以覆盖的方式写入 ls -al >> test 以追加的方式写入 二 . 输入重定向(将文件的内容重定向 ...
- 关于几个vcenter的合并心得!
由于最近公司领导觉得公司几个vcenter管理的不同网段IP,办公的时候操作不方便,故本人把几个vcenter上面的esxi主机合并到一个里面! 通过几次测试,发现最简单的方法就是直接用一台vcent ...
- Node.js Event Loop 的理解 Timers,process.nextTick()
写这篇文章的目的是将自己对该文章的理解做一个记录,官方文档链接The Node.js Event Loop, Timers, and process.nextTick() 文章内容可能有错误理解的地方 ...
- PAT甲题题解-1103. Integer Factorization (30)-(dfs)
该题还不错~. 题意:给定N.K.P,使得可以分解成N = n1^P + … nk^P的形式,如果可以,输出sum(ni)最大的划分,如果sum一样,输出序列较大的那个.否则输出Impossible. ...
- C#简述(三)
详细请参考:http://www.runoob.com/csharp/csharp-string.html 1.C# 字符串(String) 在 C# 中,可以使用字符数组来表示字符串,但是,更常见的 ...
- Gerrit 配置同步到多个仓库
1.修改replication.config文件 [remote "xxx"] projects = Yilule.Core.Service #aliyun仓库 url = git ...