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 ...
随机推荐
- 再聊语言,模式,OOD
今天与人再次聊到这个话题,有人在为"到底该用什么模式"而烦恼,我相信,每个都经历过这个阶段一定都会感觉很熟悉这个烦恼我认为, 模式不是目的,只是工具,达到设计目标的工具,我们不会因 ...
- gcc、make、makefile、cmake、cmakelists区别
文章来源:见下! 作者:辉常哥链接:https://www.zhihu.com/question/36609459/answer/89743845来源:知乎著作权归作者所有.商业转载请联系作者 ...
- 洛谷P2278 [HNOI2003] 操作系统
题目传送门 分析:题目中提到了优先级,很显然这题要用优先队列+模拟.题目中很多细节需要注意,还是在代码中解释吧,这里我用的是手打的堆. Code: #include<bits/stdc++.h& ...
- python中join函数的用法
这个函数可以对字符串按照某种方式进行拼接,比如你要在三个字母中间都添加一个特定字符,就可以用这个函数实现 result = '*'.join(['A','B','C']) print(result) ...
- Standard Java集合类问题待整理
1. HashSet.LinkedHashSet和TreeSet HashSet采用散列函数对元素进行排序,是专门为快速查询而设计的.存入HashSet的对象必须定义hashCode方法. TreeS ...
- 【BZOJ 1815】【SHOI 2006】color 有色图
http://www.lydsy.com/JudgeOnline/problem.php?id=1815 这道题好难啊,组合数学什么根本不会啊qwq 题解详见08年的Pólya计数论文. 主要思想是只 ...
- 【推导】计蒜客17116 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 C. Sum
题意:S(x)被定义为x的十进制表示下的数位之和.给你x,让你找一个正整数k,使得S(kx)能被233整除.k不超过2千位. 由于x不超过1000000,不论x是多少,10000000重复233次一定 ...
- 【状压dp】CDOJ1608 暑假集训
裸的状压的话,很显然……但有一个强大的优化. 就是在枚举决策的时候,固定第一个空位置.可以证明,这样状态数没有减少,但是降低了很多重复访问. 因为你在枚举的时候,总是可以划分为包含第一个空位置的3个位 ...
- 【并查集】POJ2236-Wireless Network
[题目大意] 已知每一台电脑只能与它距离为d的电脑相连通,但是两台电脑间可以以第三台作为媒介连接.现在电脑全被损坏.每次可以进行两个操作中的一个,或是修好一台电脑,或是查询两台电脑是否连通. [思路] ...
- echarts 关系图graph force布局 拖动节点并固定不返回原点
myChart.on('mouseup',function(params){var option=myChart.getOption();option.series[0].nodes[params.d ...