题目

这里的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 (最短路变种,连通图的最长边)的更多相关文章

  1. POJ 2253 Frogger 最短路 难度:0

    http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...

  2. POJ 2253 Frogger (最短路)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28333   Accepted: 9208 Descript ...

  3. poj 2253 Frogger(最短路 floyd)

    题目:http://poj.org/problem?id=2253 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元 ...

  4. POJ 2253 Frogger -- 最短路变形

    这题的坑点在POJ输出double不能用%.lf而要用%.f...真是神坑. 题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值. 算法:Dijkstra 题目每次选择权值最小的边进行延伸访 ...

  5. POJ 2253 Frogger ( 最短路变形 || 最小生成树 )

    题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...

  6. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  7. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  8. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  9. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

随机推荐

  1. FPGA笔记-读取.dat文件

    读取.dat图像文件 .dat文件是matlab生成的图像文件 initial begin // Initialize Inputs CLK = 0; RST = 1; IMAGE_DATA = 0; ...

  2. Mysql 存储程序

    #1存储过程create procedure greeting() BEGIN # 77 = 16 FOR username + 60 for hostname + 1 for '@' DECLARE ...

  3. 不同浏览器的DNS超时重发机制(一)

    一.Chrome浏览器(37.0.2062.124 m) 1.在Win7环境下,DNS超时重发的时间间隔为:2s.2s.2s.2s(在这个时刻重复发2个DNS请求).2s.4s,再经过大约14s左右, ...

  4. Linux下mysql的安装和使用(C语言)

    1 mysql的安装 我使用的ubuntu在线安装,非常简单,命令为: sudo apt-get install mysql-client mysql-server 2 mysql命令集合 网络太多了 ...

  5. MongoDB如何存储数据

    想要深入了解MongoDB如何存储数据之前,有一个概念必须清楚,那就是Memeory-Mapped Files. Memeory-Mapped Files 下图展示了数据库是如何跟底层系统打交道的. ...

  6. Apache 的 Rewrite 规则详细介绍

    Rewrite标志: R[=code](force redirect) 强制外部重定向 F(force URL to be forbidden) 禁用URL,返回403HTTP状态码 G(force ...

  7. LANMP 如何禁止访问 .htaccess 文件

    很多朋友问我,为什么他已经在 Apache 规则里面加了禁止别人直接下载 .htaccess 文件,为什么还是可以下载? 其实这个很简单,因为 .htaccess 在 LANMP 环境下,当他作为文件 ...

  8. 使用VideoView播放、暂停、快进视频

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&qu ...

  9. Microsoft Azure Preview portal 以及Preview Features介绍

    首先mooncake版本并不提供此类功能. 国际版会把将来推出的功能提供Preview,而且是免费的,有想研究未来技术以及的同学可以尝试 通过以下地址进入国际版,往下拉 http://azure.mi ...

  10. hive中简单介绍分区表

    所介绍内容基本上是翻译官方文档,比较肤浅,如有错误,请指正! hive中创建分区表没有什么复杂的分区类型(范围分区.列表分区.hash分区.混合分区等).分区列也不是表中的一个实际的字段,而是一个或者 ...