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 ...
随机推荐
- 对于String对象,可以使用"="赋值,也可以使用"new"关键字赋值,两种方式有什么区别?
当你看见这个标题的时候,你可能会下意识的去想一下,这两种方式到底有什么样的区别呢? 且看下面的demo,自然便区分开了 /** * */ package com.b510.test; /** * Pr ...
- 模板引擎freemarker的简单使用教程
freemarker十分强大,而且不依赖web容器,个人感觉十分好用. 下面直接进主题,freemarker还有什么特性,请找度娘或谷哥~ 一.freemarker生成word 1.创建模板. 我创建 ...
- SSH自定义分页标签
本文参考文章:http://blog.csdn.net/qjyong/article/details/3240303 一.标签处理类: package cn.conris.sys.form; impo ...
- UIView+LHQExtension(分类)
// // UIView+LHQExtension.h // 微博 - 李洪强(2016-5-27) // // Created by vic fan on 16/5/30. // Copyr ...
- kvm快照
Kvm快照: 1.基于lvm的快照 2.kvm自带的快照功能(需要qcow2 磁盘文件才支持快照) 关闭kvm虚拟机: 查看磁盘文件信息: [root@super67 ~]# qemu-img inf ...
- MySQL中的datetime与timestamp比较-------转载
原文地址http://database.51cto.com/art/200905/124240.htm MySQL中的datetime与timestamp比较 本文将通过实例比较MySQL中的date ...
- PHPExcel 是用来操作Office Excel 文档的一个PHP类库
PHPExcel 是用来操作Office Excel 文档的一个PHP类库,它基于微软的OpenXML标准和PHP语言.可以使用它来读取.写入不同格式的电子表格,如 Excel (BIFF) .xls ...
- avira更新时候安装了launcher
用不上红伞其他的软件,一个登录选择器就显得多余.可能是长时间没用电脑,更新给装上了启动器. 本文以时间顺序而记录 ------------------------------------------- ...
- [ZZ] The Naked Truth About Anisotropic Filtering
http://www.extremetech.com/computing/51994-the-naked-truth-about-anisotropic-filtering In the seemin ...
- jQuery 判断表单中多个 input text 中至少有一个不为空
html: 名称1:<input class="seasoning_name" type="text" name="seasoning_name ...