最短路径变形 POJ 2253
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
Input
Output
Sample Input
2
0 0
3 4 3
17 4
19 4
18 5 0
Sample Output
Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414 题目大意:第一个点是起点 ,第二个点是终点其余点是起点和终点之间的点,问从起点到终点最短路上两点之间最远的距离。
这是一个最短路变形问题,dis数组保存的不再是到某一点的最短路径,而是路径上两点之间的最远距离
转移方程dis[i]=min(dis[i],max(ans,arr[pos][i]))
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1e4+;
const double INF=1e7+;
int n;
struct stu{
int a,b;
}p[N];
int mark[N];
double arr[N][N];
double dis[N];
void djstrea(){
memset(mark,,sizeof(mark));
for(int i=;i<=n;i++){
dis[i]=arr[][i];
}
dis[]=;
mark[]=;
for(int i=;i<=n;i++){
double ans=INF;
int s;
for(int i=;i<=n;i++)
if(mark[i]==&&ans>dis[i]){
ans=dis[i];
s=i;
}
mark[s]=;
for(int i=;i<=n;i++){
if(mark[i]==){
dis[i]=min(dis[i],max(ans,arr[s][i]));//转移方程变啦
}
}
}
}
int main(){
int k=;
int x,y;
while(scanf("%d",&n)&&n){
k++;
for(int i=;i<=n;i++){
cin>>x>>y;
p[i].a=x;
p[i].b=y;
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
arr[i][j]=arr[j][i]=INF; for(int i=;i<n;i++){
for(int j=i+;j<=n;j++){
arr[j][i]=arr[i][j]=sqrt((p[i].a-p[j].a)*(p[i].a-p[j].a)+(p[i].b-p[j].b)*(p[i].b-p[j].b));
}
}
djstrea();
printf("Scenario #%d\n",k);
printf("Frog Distance = %.3f\n",dis[]);
cout<<endl;
}
return ;
}
也可以用flord写:
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define maxnum 300
#define inf 0x3f3f3f3f
using namespace std;
int x[maxnum],y[maxnum],n;
double map[maxnum][maxnum];
void floyd()
{
for(int k=; k<=n; k++)
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
map[i][j]=min(map[i][j],max(map[i][k],map[k][j]));//许多通路中最长边中的最小边
// map[i][j]=min(map[i][j],max(map[i][k],map[k][j]));
}
int main()
{
int q=;
while(~scanf("%d",&n)&&n)
{
mem(map,);
for(int i=; i<=n; i++)
scanf("%d%d",&x[i],&y[i]);
for(int i=; i<=n; i++)
for(int j=i+; j<=n; j++)
map[i][j]=map[j][i]=sqrt(double(x[i]-x[j])*(x[i]-x[j])+double(y[i]-y[j])*(y[i]-y[j]));
floyd();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",q++,map[][]);
}
return ; }
最短路径变形 POJ 2253的更多相关文章
- poj 2253 (dis最短路径)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24979 Accepted: 8114 Descript ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
- 最短路(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 (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 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变形——最短路径最大权值)
题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...
- [ACM] POJ 2253 Frogger (最短路径变形,每条通路中的最长边的最小值)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24879 Accepted: 8076 Descript ...
随机推荐
- java触发full gc的几种情况概述
前言 近期被问及这个问题,在此记录整理一下. System.gc()方法的调用 此方法的调用是建议JVM进行Full GC,虽然只是建议而非一定,但很多情况下它会触发 Full GC,从而增加Full ...
- 201771010103 陈亚茹 《面向对象程序设计(java)》第一周学习总结
本人学号<面向对象程序设计(java)>第一周学习总结 第一部分:课程准备部分 填写课程学习 平台注册账号, 平台名称 注册账号 博客园:www.cnblogs.com https://w ...
- [模拟] Codefroces 1175B Catch Overflow!
题目:http://codeforces.com/contest/1175/problem/B B. Catch Overflow! time limit per test 1 second memo ...
- 算法训练 瓷砖铺放 【递归】java
算法训练 瓷砖铺放 时间限制:1.0s 内存限制:512.0MB 锦囊1 锦囊2 锦囊3 问题描述 有一长度为N(1<=N<=10)的地板,给定两种不同瓷砖:一种长度为 ...
- ML Lecture 0-1: Introduction of Machine Learning
本博客是针对李宏毅教授在Youtube上上传的课程视频<ML Lecture 0-1: Introduction of Machine Learning>的学习笔记.在Github上也po ...
- 搞定SEO,看这一篇就够了
一.SEO入门 1.SEO是什么? SEO(Search Engine Optimization)中文意思为搜索引擎优化.在了解搜索引擎自然排名机制的基础上,对网站进行内部及外部的调整优化,改进网站在 ...
- Python python对象 enumerate
""" enumerate(iterable[, start]) -> iterator for index, value of iterable Return a ...
- ios shell打包脚本 gym
#! /bin/bash project_path=$() project_config=Release output_path=~/Desktop build_scheme=YKTicketsApp ...
- mysql的Ft_hints: no_ranking
是不是发现找遍全网也没有找到相关资料? 巧了,我也是,所以我这里来进行一次大胆分析(基本靠猜) 在使用mysql的fulltext索引(全文索引)时,使用explain则会在extra中出现这句提示: ...
- Pytest系列(2) - assert断言详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 与unittest不同,py ...