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 ...
随机推荐
- 一个可以代替冗长switch-case的消息分发小框架
在项目中,我需要维护一个应用层的字节流协议.这个协议的每条报文都是一个字节数组,数组的头两个字节表示消息的传送方向,第三.四个字节表示消息ID,也就是消息种类,再往后是消息内容.时间戳.校验码等……整 ...
- REST-framework快速构建API--认证
一.API使用流程 使用过API的同学都知道,我们不可能任意调用人家的API,因为通过API可以获取很多关键数据,而且这个API可能供多个部门或个人使用,所以必须是经过授权的用户才能调用. API的使 ...
- Asp.net MVC Razor常见问题及解决方法(转载>云中客)
没有经验的童鞋就是这样磕磕碰碰出来的经验. 1,Datatype的错误提示消息无法自定义 这也许是Asp.net MVC的一个Bug.ViewModel中定义了DataType为Date字段: 1 2 ...
- 关于Unity物理事件的执行顺序的最新理解
物体A: public class A:{ B b; void FixedUpdate(){ if(input.GetKeyDow(Keycode.I)) { collider.enable=fals ...
- oracle创建用户和角色、管理授权以及表空间操作
show user 显示当前用户connect username/password@datebasename as sysdba 切换用户和数据库 和用户身份 Oracle登录身份有三种: norma ...
- 专业实训题目需求分析(3D推箱子)
业务需求: 游戏提供主菜单让玩家进行游戏设置.帮助说明,推箱子的小人可以前后左右转动,箱子可以被上下左右的推动,要有关卡设置,障碍物设置,游戏提供背景音乐的功能,要实现3D效果. 面向的用户类型 ...
- [BUG随想录] 看不见的分隔符: Zero-width space
今天在调试一段代码的时候,有一个输入不能为空的库函数抛出了异常(为空就会抛出异常,就是这么傲娇).自己暗骂了自己一番,怎么这么大意,于是追溯源头,开始寻找输入控制的地方.但是当我找到时我惊呆了,我明明 ...
- Mysql设置允许外网访问(图文)
1.打开mysql.exe(MySQL Command Line Client),输入密码 2.输入:use mysql; 3.查询host输入: select user,host from user ...
- Photoshop的混合模式
1.亮度是一种颜色的相对亮度,饱和度是指一种颜色的纯度(颜色中包含多少灰) 2.混合模式 下层图片的颜色像素称为"基本颜色":选定的称为"混合"颜色,对于大部分 ...
- 防止短时间js 重复执行
function debounce(fn, delay) { // 持久化一个定时器 timer let timer = null; // 闭包函数可以访问 timer return function ...