Subway---poj2502(最短路)
题目链接:http://poj.org/problem?id=2502
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include <string>
typedef long long LL;
#define INF 1e30
#define met(a, b) memset(a, b, sizeof(a))
#define N 515 using namespace std; struct node
{
double x,y;
}a[N]; double G[N][N], dist[N];
int vis[N], cnt; double Dij(int s)
{
met(vis, );
for(int i=; i<=cnt; i++)
dist[i] = INF;
dist[s] = ;
for(int i=; i<cnt; i++)
{
double Min = INF; int Index = -;
for(int j=; j<cnt; j++)
{
if(!vis[j] && Min>dist[j])
{
Min = dist[j];
Index = j;
}
}
if(Index == -)break;
vis[Index] = ;
for(int j=; j<cnt; j++)
{
if(!vis[j] && dist[j]>dist[Index]+G[Index][j])
{
dist[j] = dist[Index]+G[Index][j];
}
}
}
return dist[];
} int main()
{
while(scanf("%lf %lf %lf %lf", &a[].x, &a[].y, &a[].x, &a[].y)!=EOF)
{
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
G[i][j] = INF;
G[i][i] = ;
}
cnt = ; int pre = -; double x, y;
while(scanf("%lf %lf", &x, &y) != EOF)
{
if(x == - && y == -)
{
pre = -;
continue;
}
a[cnt].x = x, a[cnt].y = y;
if(pre!=-)
{
double d = sqrt((a[pre].x-x)*(a[pre].x-x)+(a[pre].y-y)*(a[pre].y-y));
G[pre][cnt] = G[cnt][pre] = min(G[cnt][pre], d*3.0/);
}
pre = cnt++;
} for(int i=; i<cnt; i++)
{
for(int j=; j<cnt; j++)
{
double d = sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
G[i][j] = G[j][i] = min(G[i][j],d*6.0/);
}
} double ans = Dij();
printf("%.0f\n", ans);
}
return ;
}
Subway---poj2502(最短路)的更多相关文章
- POJ2502:Subway(最短路)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14634 Accepted: 4718 题目链接:http ...
- POJ 2502 Subway (最短路)
Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...
- poj2502 最短路
//Accepted 504 KB 16 ms //spfa最短路 //把n个地铁站作为n个顶点,边权为从一个站到另一个站的时间 //注意:地铁在相邻的两站之间是直线行驶,但其他的就不是了 #incl ...
- poj2502最短路!
have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride ...
- AtCoder ARC061E Snuke's Subway Trip 最短路
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门 Portal 原题目描述在最下面. \(n(1 ...
- POJ-2502(Dijikstra应用+最短路)
Subway POJ-2502 这里除了直接相连的地铁站,其他图上所有的点都要连线,这里是走路的速度. 记住最后的结果需要四舍五入,否则出错. #include<iostream> #in ...
- kuangbin 最短路集合
Til the Cows Come Home poj-2387 #include<iostream> #include<cstdio> #include<algorith ...
- atcoder题目合集(持续更新中)
Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...
- POJ-2502 Subway( 最短路 )
题目链接:http://poj.org/problem?id=2502 Description You have just moved from a quiet Waterloo neighbourh ...
- L - Subway(最短路spfa)
L - Subway(最短路spfa) You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. In ...
随机推荐
- (转)js:字符串(string)转json
第一种方式: 使用js函数eval(); testJson=eval(testJson);是错误的转换方式. 正确的转换方式需要加(): testJson = eval("(" + ...
- JAVA排序算法
]; ; i < ; i++){ sort[i] = ran.nextInt(); } System.out.print(;i<sort.length;i++){ ;j<sort ...
- <!--[if IE]>….<![endif]--> (<!--[if !IE]>||<![endif]-->)的用法
1. <!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--> 2. <!--[if IE]> 所有的IE可识别 ...
- php的具体配置学习笔记
1.将php配置为apache的一个模块,使用loadmodule指令完成. 2.写下面的语句,此外需强调的是,每次配置都需要重新启动apache 3.php文件,要指定将其php模块来处理 4.PH ...
- PHP一般情况下生成的缩略图都比较不理想
PHP用GD库生成高质量的缩略图片,PHP一般情况下生成的缩略图都比较不理想.今天试用PHP,GD库来生成缩略图.虽然并不100%完美.可是也应该可以满足缩略图的要求了.<?php $FILEN ...
- [服务器]脚本:批处理带参数ping命令 发送邮件脚本
1.批处理带参数ping命令 @echo offecho Input you IP address ......set /p IP=echo Your IP number is %IP%.ping % ...
- Frenetic Python实验(二)
实验3 packet_in_out 目的:模拟一个普通的双端口中继器. This application implements a very simple 2 port repeater where ...
- 使用phpstorm和xdebug实现远程调试
使用phpstorm和xdebug实现远程调试 2012-05-23 10:06:35 vs的断点调试功能很强大有木有,能查看所有变量有木有.php调试很麻烦有木有,echo,var_dump写得你想 ...
- 推荐!国外程序员整理的 PHP 资源大全
推荐!国外程序员整理的 PHP 资源大全 2014/08/02 · PHP, 工具与资源 · 8.5K 阅读 · 1 评论· php 分享到:0 与<YII框架>不得不说的故事—安全篇 R ...
- RT-Thread的CPU使用率计算
CPU 的使用率一般是我们比较关心的问题,在这里我们就用空闲线程的钩子函数去统计 CPU 的使用率,并通过串口打印出来.首先我们在初始化线程中设置好钩子函数,并在 LED 线程中给系统人为的加入很多“ ...