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 ...
随机推荐
- BZOJ3853 : GCD Array
1 n d v相当于给$a[x]+=v[\gcd(x,n)=d]$ \[\begin{eqnarray*}&&v[\gcd(x,n)=d]\\&=&v[\gcd(\fr ...
- 大白话strom——问题收集(持续更新ing)
本文导读: 1.基于storm的应用 2.storm的单点故障解决 3.strom与算法的结合学习4.杂记——常见问题的解答5.http://www.blogchong.com/catalog.asp ...
- 【原】storm源码之storm代码结构【译】
说明:本文翻译自Storm在GitHub上的官方Wiki中提供的Storm代码结构描述一节Structure of the codebase,希望对正在基于Storm进行源码级学习和研究的朋友有所帮助 ...
- 【BZOJ】1074: [SCOI2007]折纸origami
http://www.lydsy.com/JudgeOnline/problem.php?id=1074 题意:一开始有一个左上角是(0,100),右下角是(100,0)的纸片,现在可以沿有向直线折n ...
- JAVA String.format 方法使用介绍
1.对整数进行格式化:%[index$][标识][最小宽度]转换方式 我们可以看到,格式化字符串由4部分组成,其中%[index$]的含义我们上面已经讲过,[最小宽度]的含义也很好理解, ...
- CSS权威指南 - 浮动和定位 1
定位 定位的想法很简单元素框相对于正常位置出现在哪里. 定位:static,相对, 绝对, fixed, 继承 static就是默认的位置 相对就是相对于默认位置的偏移.原来的static定位位置依然 ...
- POJ 1185 经典状压dp
做了很久的题 有注释 #include<stdio.h> #include<string.h> #include<algorithm> #include<ma ...
- FZU 2124 bfs+vis记录
第一次团队训练赛的题 自己看完题没看到不能用舌头吃道具..以为是什么贪心混合bfs..果断放弃..悄悄的背锅了 然后其实比较简单 只是利用vis记录的时候要分两种状态记录 有没有道具 每到一个地方 就 ...
- twitter storm源码走读之1 -- nimbus启动场景分析
欢迎转载,转载时请注明作者徽沪一郎及出处,谢谢. 本文详细介绍了twitter storm中的nimbus节点的启动场景,分析nimbus是如何一步步实现定义于storm.thrift中的servic ...
- PHP函数库(other)
PHP函数库(other) Session函数: session_abort — Discard session array changes and finish session session_ab ...