最短路径变形 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 ...
随机推荐
- [单调栈] 2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest-Maximum Element In A Stack
题目:https://codeforces.com/gym/102222/problem/A Maximum Element In A Stack time limit per test 10.0 s ...
- UVA11987 Almost Union-Find 并查集的节点删除
题意: 第一行给出一个n,m,表示 n个集合,里面的元素为1~n,下面有m种操作,第一个数为 1 时,输入a,b 表示a,b 两个集合合并到一起,第一个数为 2 时,输入a,b表示将 a 从他原来的集 ...
- arcgis10.4.X的oracle数据库要求
受支持的数据库版本:(标准版/标准独立版/企业版) Oracle 11g R2(64 位)11.2.0.4 Oracle 12c R1(64 位)12.1.0.2 受支持的操作系统: 数据库 支持的操 ...
- 分库分表实践-Sharding-JDBC
最近一段时间在研究分库分表的一些问题,正好周末有点时间就简单做下总结,也方便自己以后查看. 关于为什么要做分库分表,什么是水平分表,垂直分表等概念,相信大家都知道,这里就不在赘述了. 本文只讲述使用S ...
- Vue 里面对树状数组进行增删改查 的方法
[{"id":"5e4c3b02fc984961a17607c37712eae0", "optLock":0, "parentId ...
- vue 动态添加body背景图片
<script> export default { data () { return { bodyBgImage: 'url(' + require('../asse ...
- 记python 链式比较的坑
前两天,python交流群里有人问: “x”<"y"==True 这个表达式输出的是什么,脑子都没动,就觉得应该是True 居然被否定了!立马在命令行里敲了一下,准备用事实打 ...
- PTA数据结构与算法题目集(中文) 7-4
PTA数据结构与算法题目集(中文) 7-4 是否同一颗二叉搜索树 给定一个插入序列就可以唯一确定一棵二叉搜索树.然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到.例如分别按照序列{2, 1, ...
- Maven快照版本要这样用才真的香!
Bug的身世之谜 今天又分享一个问题解决的故事.请看下图框起来的错误,明显就是找不到这个class嘛! 下面我们按照正常人的思路去排查这个问题,既然找不到class那就先看这个依赖的jar包有没有,如 ...
- 记一次mysql多表查询(left jion)优化案例
一次mysql多表查询(left jion)优化案例 在新上线的供需模块中,发现某一个查询按钮点击后,出不来结果,找到该按钮对应sql手动执行,发现需要20-30秒才能出结果,所以服务端程序判断超时, ...