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 ...
随机推荐
- python zip enumerate函数
zip是一个内置函数, 接受两个或多个序列,并将他们拉到一起,成为一个元组列表.每个元组包含各个序列中的一个元素. s = 'abc' t = [0,1,2] zip(s,t) >>> ...
- Graph database_neo4j 底层存储结构分析(5)
3.5 Property 的存储 下面是neo4j graph db 中,Property数据存储对应的文件: neostore.propertystore.db neostore.propertys ...
- 《Lucene实战(第2版)》 配书代码在IDEA下的编译方法
参考: hankcs http://www.hankcs.com/program/java/lucene-combat-2nd-edition-book-with-code-compiled-unde ...
- SqlParameter 基本用法
因为通过SQL 语句的方式,有时候存在脚本注入的危险,所以在大多数情况下不建议用拼接SQL语句字符串方式,希望通过SqlParameter实现来实现对数据的操 作,针对SqlParameter的方式我 ...
- fastjson生成json时Null属性不显示
举个例子 生成JSON代码片段 Map < String , Object > jsonMap = new HashMap< String , Object>(); jsonM ...
- PHP 错误与异常 笔记与总结(8)自定义错误处理函数 set_error_handler()
通过 Set_error_handler() 函数设置用户自定义的错误处理函数. 步骤: ① 创建错误处理函数 ② 设置不同级别调用函数 ③ Set_error_handler() 函数制定接管错误处 ...
- [转]通过Mesos、Docker和Go,使用300行代码创建一个分布式系统
http://www.csdn.net/article/2015-07-31/2825348 [编者按]时下,对于大部分IT玩家来说,Docker和Mesos都是熟悉和陌生的:熟悉在于这两个词无疑已成 ...
- javaWeb中struts开发——Logic标签
1.Struts标签的logic标签 Logic标签是逻辑标签,是Struts中比较重要的标签,完成各种逻辑运算操作,可以直接支持全局调转. 2.1<logic:present><l ...
- 学习之道-从求和起-求和曲线面积瞬时速率极限微积分---求和由高解低已知到未知高阶到低阶连续自然数的K次方之和
数学分析 张筑生
- design the relations
Computer Science An Overview _J. Glenn Brookshear _11th Edition A pivotal step in designing a relati ...