poj 2253 Frogger (最长路中的最短路)
题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B,
问从A到B多条路径中的最长边中的最短距离
分析:这题是最短路的变形,曾经求的是路径总长的最小值,而此题是通路中最长边的最小值,每条边的权值能够通过坐标算出,由于是单源起点,直接用SPFA算法或dijkstra算法就能够了
SPFA 16MS
#include<cstdio>
#include<queue>
#include<cmath>
#include<climits>
using namespace std;
double a[205][205],dis[205];
int vis[205];
double max(double a,double b)
{
return a>b?a:b;
}
void SPFA(int n)
{
queue<int> q;
int i,j;
for(i=2;i<=n;i++){
dis[i]=INT_MAX;
vis[i]=0;
}
dis[1]=0;
q.push(1);
vis[1]=1;
while(!q.empty()){
i=q.front();
q.pop();
vis[i]=0;
for(j=1;j<=n;j++)
if(dis[j]>max(dis[i],a[i][j])){
dis[j]=max(dis[i],a[i][j]);
if(!vis[j]){
q.push(j);
vis[j]=1;
}
}
}
}
int main()
{
int i,j,n,k=0,x[205],y[205];
while(scanf("%d",&n)!=EOF){
if(n==0)
break;
k++;
printf("Scenario #%d\n",k);
for(i=1;i<=n;i++)
scanf("%d%d",&x[i],&y[i]);
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
a[i][j]=a[j][i]=sqrt(double(x[i]-x[j])*(x[i]-x[j])+double(y[i]-y[j])*(y[i]-y[j]));
SPFA(n);
printf("Frog Distance = %.3lf\n\n",dis[2]);
}
return 0;
}
poj 2253 Frogger (最长路中的最短路)的更多相关文章
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- [ACM] POJ 2253 Frogger (最短路径变形,每条通路中的最长边的最小值)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24879 Accepted: 8076 Descript ...
- POJ 2253 Frogger【最短路变形/最小生成树的最大权/最小瓶颈树/A到B多条路径中的最小的最长边】
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- POJ 2253 Frogger(floyd)
http://poj.org/problem?id=2253 题意 : 题目是说,有这样一只青蛙Freddy,他在一块石头上,他呢注意到青蛙Fiona在另一块石头上,想去拜访,但是两块石头太远了,所以 ...
随机推荐
- jquery 拓展方法
摘抄自(http://hi.baidu.com/jjjvzugcpmcdmor/item/0e32a89c36a18544f04215d7) $.fn是指jquery的命名空间,加上fn上的方法及属性 ...
- 如何去掉List中的重复内容
1.通过循环进行删除 public static void removeDuplicate(List list) { ; i < list.size() - ; i ++ ) { ; j > ...
- Android中网络流量控制(防火墙)——Iptables
Iptables简单介绍 iptables是与最新的 2.6.x 版本号 Linux 内核集成的 IP 信息包过滤系统. 假设 Linux 系统连接到因特网或 LAN.server或连接 LAN 和因 ...
- poj2299--B - Ultra-QuickSort(线段树,离散化)
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 41215 Accepted: 14915 ...
- OCP读书笔记(14) - 管理数据库性能
搜集统计信息 1. dbms_stats gather_schema_stats 1)option:有四个选项: a.gather empty:只分析目前还没有搜集过统计信息的表 SQL> co ...
- zoj 2822 Sum of Different Primes (01背包)
///给你n 求他能分解成多少个的不同的k个素数相加之和 ///01背包,素数打表 # include <stdio.h> # include <algorithm> # in ...
- freemarker自己定义标签(二)
freemarker自己定义标签 1.自己定义标签 通过自己定义标签,写一个反复指定字符串 2.实现源代码 <html> <head> <meta http-equiv= ...
- Git详解之六 Git工具(转)
Git 工具 现在,你已经学习了管理或者维护 Git 仓库,实现代码控制所需的大多数日常命令和工作流程.你已经完成了跟踪和提交文件的基本任务,并且发挥了暂存区和轻量级的特性分支及合并的威力. 接下来你 ...
- Flexigrid的使用(整合Struts2)
Flexigrid是一个jQuery表格插件 下载地址:http://download.csdn.net/detail/itmyhome/7613879 用法: 一.相关资源文件的引入 <lin ...
- 使用SVN clang: error: linker command failed with exit code 1 (use -v to see invocation)
然后上传到该项目SVN仓库上,例如,下面的错误再次发生再拉到本地编译 ld: library not found for -lxxxxxxxxxxxx clang: error: linker com ...