最短路(Floyd_Warshall) POJ 2253 Frogger
/*
最短路:Floyd算法模板题
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
using namespace std; const int MAXN = + ;
const int INF = 0x3f3f3f3f;
double d[MAXN][MAXN];
int used[MAXN];
struct NODE
{
int x, y;
}node[MAXN]; double dis(int j, int i)
{
return sqrt ((node[j].x - node[i].x) * (node[j].x - node[i].x) + (node[j].y - node[i].y) * (node[j].y - node[i].y));
} void Floyd_Warshall(int n)
{
for (int k=; k<=n; ++k)
{
for (int i=; i<=n-; ++i)
{
for (int j=i+; j<=n; ++j)
{
if (d[i][k] < d[i][j] && d[k][j] < d[i][j])
{
if (d[i][k] < d[k][j])
d[i][j] = d[j][i] = d[k][j];
else
d[i][j] = d[j][i] = d[i][k];
}
}
}
} printf ("Frog Distance = %.3f\n", d[][]);
} int main(void) //POJ 2253 Frogger
{
//freopen ("D.in", "r", stdin); int n;
int cnt = ;
int first = ;
while (~scanf ("%d", &n) && n)
{
for (int i=; i<=n; ++i)
{
scanf ("%d%d", &node[i].x, &node[i].y);
}
for (int i=; i<=n-; ++i)
{
for (int j=i+; j<=n; ++j)
{
d[i][j] = d[j][i] = dis (i, j);
}
} printf ("Scenario #%d\n", ++cnt);
Floyd_Warshall (n);
puts ("");
} return ;
} /*
Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414
*/
最短路(Floyd_Warshall) POJ 2253 Frogger的更多相关文章
- [kuangbin带你飞]专题四 最短路练习 POJ 2253 Frogger
求第一个点到第二个点的所有通路上最长的边 dijkstra的变形 每次松弛的是每条边通路上的的最长的边 WA了好几次是因为用了%lf 改成%f就过了…… /* ******************** ...
- 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可行 ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
随机推荐
- tolua.cast的实用方法
local name = (tolua.cast(sender, "ccui.Button")):getTitleText()
- cocos2d调度器(定时执行某函数)
调度器(scheduler) 继承关系 原理介绍 Cocos2d-x调度器为游戏提供定时事件和定时调用服务.所有Node对象都知道如何调度和取消调度事件,使用调度器有几个好处: 每当Node不再可见或 ...
- 默认hosts后面为files dns
售后工程师 : 您好,问题已经解决,问题原因是您修改了/etc/nsswitch.conf配置文件中的hosts:这项导致的,默认hosts后面为files dns,但是后面去掉了DNS导致直接使用本 ...
- Shell之date用法
创建以当前时间为文件名的 mkdir `date+%Y%m%d` 备份以时间做为文件名的 tar cvf./htdocs`date +%Y%m%d`.tar ./* date命令如何获得上星期的日期? ...
- Java异常的栈轨迹fillInStackTrace和printStackTrace的用法
本文转自wawlian 捕获到异常时,往往需要进行一些处理.比较简单直接的方式就是打印异常栈轨迹Stack Trace.说起栈轨迹,可能很多人和我一样,第一反应就是printStackTrace()方 ...
- selec2 clone不起作用。
<table class="table table-bordered"> <thead> <tr> <th width ="16 ...
- Light OJ 1393 Crazy Calendar (尼姆博弈)
C - Crazy Calendar Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Su ...
- C语言字符串处理
一. C语言中,为什么字符串可以赋值给字符指针变量 char *p,a='5';p=&a; //显然是正确的,p="abcd"; ...
- [产品相关] A/B测试终极指南(翻译)
转载地址: http://blog.sina.com.cn/s/blog_9149268d0100zrx7.html 还记得以前导师说看了英文的文章就把它翻译一下吧,这样会对文章更好地理解,也会有更深 ...
- javaScript中利用ActiveXObject来创建FileSystemObject操作文件
注:如果用javascript读本地文件,遇到安全问题. 需在浏览器中进行设置,如下: 工具—> Internet选项->安全->自定义级别->启用“没有标识为安全的A ...