poj 2253 (dis最短路径)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 24979 | Accepted: 8114 |
Description
by jumping.
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
stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.
Output
after each test case, even after the last one.
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
Source
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
double G[210][210];
int n;
struct Point{
double x,y;
}a[210];
float dist(Point a,Point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void dij(){
double dis[210];
int vis[210];
for(int i=1;i<=n;i++)
vis[i]=0;
vis[1]=1;
dis[1]=0.0;
for(int i=2;i<=n;i++)
dis[i]=G[1][i];
for(int i=1;i<n;i++){
double min=999999.0;
int v;
for(int j=2;j<=n;j++)
if(!vis[j] && dis[j]<min){
min=dis[j];
v=j;
}
vis[v]=1;
for(int j=1;j<=n;j++){
double tmp=(dis[v]<G[v][j] ? G[v][j] : dis[v]); //注意这里是最短路径变形
dis[j]= tmp<dis[j] ? tmp : dis[j];
}
}
cout<<setiosflags(ios::fixed)<<setprecision(3)<<dis[2]<<endl<<endl;
}
int main(){
int cas=1;
while(cin>>n&&n){
for(int i=1;i<=n;i++)
cin>>a[i].x>>a[i].y;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
G[i][j]=dist(a[i],a[j]);
cout<<"Scenario #"<<cas++<<endl;
cout<<"Frog Distance = ";
dij();
}
return 0;
}
poj 2253 (dis最短路径)的更多相关文章
- poj 2253 Frogger (最短路径)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22557 Accepted: 7339 Descript ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- 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 )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)
题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...
- 最短路径变形 POJ 2253
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...
随机推荐
- thinkphp下实现ajax无刷新分页
1.前言 作为一名php程序员,我们开发网站主要就是为了客户从客户端进行体验,在这里,thinkphp框架自带的分页类是每次翻页都要刷新一下整个页面,这种翻页的用户体验显然是不太理想的,我们希望每次翻 ...
- ubuntu安装wine
1.安装源 sudo add-apt-repository ppa:wine/wine-builds sudo apt-get update 2.安装wine sudo apt-get install ...
- Java HashSet的元素内容变化导致的问题
概述 HashSet元素引用的对象的内容发生变化,会导致"元素不属于集合"的问题.事实上这个元素还在集合里,但是调用contains方法进行判断,得到的结果却是false. 正文 ...
- Java Eclipse插件
EasyExplore 快速打开文件所在目录1 http://sourceforge.net/projects/easystruts/ OpenExplorer 快速打开文件所在目录2 https:/ ...
- HttpClient不同版本超时时间的设置
引自 https://www.cnblogs.com/hisunhyx/p/5028391.html 3.X是这样的 HttpClient client=new DefaultHttpClient() ...
- ARM开发板不工作的几个原因
刚焊了5块ARM(LPC2478)的开发板,上程序测试了一下,发现只有一个板子工作其他四个全部歇菜.努力地找了一会最终发现是板子的来个电阻焊翻了.因为是1206 的封装而且来个电阻在PCB上摆放的位置 ...
- RabbitMQ (十三) 集群+单机搭建(window)
拜读了网上很多前辈的文章,对RabbitMQ的集群有了一点点认识. 好多文章都说到,RabbitMQ的集群分为普通集群和镜像集群,有的还加了两种:单机集群和主从集群. 我看来看去,看了半天,怎么感觉, ...
- Git Bash 将本地代码提交到Github
前提:已拥有Token,并且把本地的Token配置到了自己的Github里面(没有Token的自行去百度如何配置Token) 测试一下自己的连接 ssh -T git@github.com 本地操作: ...
- nyoj 151 Biorhythms
描述 Some people believe that there are three cycles in a person's life that start the day he or she i ...
- 主数据及其管理MDM
什么是主数据 企业数据的管理包含主数据,元数据,交易数据. 主数据是描述企业核心实体的基础数据,比如客户.用户.产品.员工等. 它是具有高业务价值的.可以在企业内跨越各个业务部门被重复使用的数据,并且 ...