poj 2253 Frogger (最短路变种,连通图的最长边)
这里的dijsktra的变种代码是我看着自己打的,终于把代码和做法思路联系上了,也就是理解了算法——看来手跟着画一遍真的有助于理解。
#define _CRT_SECURE_NO_WARNINGS #include<string.h>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std; const int MAXN=; #define typec double
const typec INF=0x3f3f3f3f*1.0;//防止后面溢出,这个不能太大
bool vis[MAXN];
typec cost[MAXN][MAXN];
typec lowcost[MAXN];
void Dijkstra(int n,int beg) //连通图的最小边——最短路变种
{
for(int i=;i<n;i++)
{
lowcost[i]=INF;vis[i]=false;
}
lowcost[beg]=0.0;
for(int i=;i<n;i++)
{
typec temp=INF;
int k=-;
for(int j=;j<n;j++)
{
if(!vis[j]&&lowcost[j]<temp)
{
temp=lowcost[j];
k=j;
}
}
vis[k]=true;
for(int l=;l<n;l++)
{
if(!vis[l])
{
lowcost[l]=min(max(lowcost[k],cost[k][l]),lowcost[l]);//原来改动在这列,具体可画图求证感知
}
}
}
} int main()
{
int n,i,j,id=;
typec a[MAXN],b[MAXN];
while(scanf("%d",&n),n)
{
for(i=;i<n;i++)
cost[i][i]=; for(i=;i<n;i++)
{
scanf("%lf%lf",&a[i],&b[i]);
for(j=;j<i;j++)
{
cost[i][j]=cost[j][i]=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
}
}
Dijkstra(n,);
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",id++,lowcost[]);
}
return ;
}
poj 2253 Frogger (最短路变种,连通图的最长边)的更多相关文章
- POJ 2253 Frogger 最短路 难度:0
http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...
- POJ 2253 Frogger (最短路)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28333 Accepted: 9208 Descript ...
- poj 2253 Frogger(最短路 floyd)
题目:http://poj.org/problem?id=2253 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元 ...
- POJ 2253 Frogger -- 最短路变形
这题的坑点在POJ输出double不能用%.lf而要用%.f...真是神坑. 题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值. 算法:Dijkstra 题目每次选择权值最小的边进行延伸访 ...
- POJ 2253 Frogger ( 最短路变形 || 最小生成树 )
题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...
- 最短路(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 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可行 ...
随机推荐
- sql临时表和表变量
1. 为什么要使用表变量 表变量是从2000开始引入的,微软认为与本地临时表相比,表变量具有如下优点: a.与其他变量的定义一样,表变量具有良好的定义范围,并会被自动清除: b.在存储过程中使用表 ...
- jquery源码分析学习地址
http://www.ccvita.com/121.htmljQuery工作原理解析以及源代码示例http://www.cnblogs.com/haogj/archive/2010/04/19/171 ...
- Windows Server 2003 IIS支持ASP
1.ASP支持是很简单的 这里简单的说一下 2.安装IIS服务 这里就不多演示了 很简单的 3.安装完成后打开IIS的扩展功能 ASP代码测试页为: <% response.write( ...
- php关联不上mysql解决办法
## php无法关联mysql php关联不上mysql解决办法: 尝试N多方法,需要的dll文件都复制了,依旧是不断提示: Fatal error: Call to undefined fun ...
- 所有外包项目威客网站列表----来自程序员接私活网qxj.me
猪八戒 http://www.zhubajie.com/ 有佣金,建议别去坑死了 csto http://www.csto.com/ 开源中国众包 https://zb.osch ...
- php数组声明、遍历、数组全局变量使用小结
数组的本质:管理和操作一组变量,成批处理,下面为大家介绍下数组的分类.数组的分类及使用说明,感兴趣的朋友可以了解下哈 php教程:数组声明,遍历,数组全局变量 <? /* * 一.数组的概 ...
- 使用mysql关键字做类字段名报的错,花了我一个钟,坑啊
com.modelsystem.po.ProjectPlan@701faaedHibernate: insert into ld.project_plan (addTime, describe, ex ...
- jqueryGrid 内置的onclickSubmit afterSubmit
$(document).ready(function() { $('#jpgCustomers').jqGrid({ //url from wich data should be requested ...
- js 数组去重复键
Array.prototype.deleteEle = function() { var newArr = this; for (var i = newArr.length - 1; i >= ...
- Linux&UNIX上卸载GoldenGate的方法
1. Log on to the database server (as oracle) where the GoldenGate software is installed. [root@oracl ...