这个题的输入输出注意一下就好

#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=4e3+;
const int INF=0x3f3f3f3f;
struct Edge{
int v,next;
double w;
bool operator<(const Edge &e)const{
return w>e.w;
}
}edge[N*N*];
int head[N],tot,n;
double d[N];
void add(int u,int v,double w){
edge[tot].v=v;
edge[tot].w=w;
edge[tot].next=head[u];
head[u]=tot++;
}
priority_queue<Edge>q;
bool vis[N];
double dij(int s,int t){
for(int i=;i<=n;++i)d[i]=INF,vis[i]=;
d[s]=,q.push(Edge{s,,});
while(!q.empty()){
while(!q.empty()&&vis[q.top().v])q.pop();
if(q.empty())break;
int u=q.top().v;
q.pop();
vis[u]=;
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].v;
if(!vis[v]&&d[v]>d[u]+edge[i].w){
d[v]=d[u]+edge[i].w;
q.push(Edge{v,,d[v]});
}
}
}
return d[t];
}
struct Point{
int x,y;
}p[N];
double dis(int i,int j){
return sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
}
int main(){
memset(head,-,sizeof(head)),tot=;
scanf("%d%d%d%d",&p[].x,&p[].y,&p[].x,&p[].y);
n=;
bool flag=;
while(~scanf("%d%d",&p[n].x,&p[n].y)){
if(p[n].x==-&&p[n].y==-){
flag=;
continue;
}
if(flag){
double tmp=dis(n,n-)/40000.0;
add(n,n-,tmp),add(n-,n,tmp);
}
flag=;
++n;
}
--n;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j){
if(i==j)continue;
double tmp=dis(i,j)/10000.0;
add(i,j,tmp),add(j,i,tmp);
}
printf("%d\n",(int)(dij(,)*60.0+0.5));
return ;
}

POJ 2502 Subway dij的更多相关文章

  1. POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离)

    POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离) Description You have just moved from a ...

  2. POJ 2502 - Subway Dijkstra堆优化试水

    做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...

  3. POJ 2502 Subway(迪杰斯特拉)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6692   Accepted: 2177 Descriptio ...

  4. POJ 2502 Subway (Dijkstra 最短+建设规划)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6689   Accepted: 2176 Descriptio ...

  5. POJ 2502 Subway

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4928   Accepted: 1602 Descriptio ...

  6. POJ 2502 Subway (最短路)

    Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...

  7. (简单) POJ 2502 Subway,Dijkstra。

    Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of ...

  8. Dijkstra+计算几何 POJ 2502 Subway

    题目传送门 题意:列车上行驶40, 其余走路速度10.问从家到学校的最短时间 分析:关键是建图:相邻站点的速度是40,否则都可以走路10的速度.读入数据也很变态. #include <cstdi ...

  9. poj 2502 Subway【Dijkstra】

    <题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...

随机推荐

  1. jQuery—一些常见方法(3)【width(),innerWidth(),outerWidth()】

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 掌握 ActionResult

    我在上一篇博客不要停留在表面,MVC 3 我们要深入一些 说明了我们的掌握程度还是不够,还需要我们继续努力.但是有园友质疑说他们认为我说的只是书院派,并不实用,这令作为程序员的我很是生气.好吧,那咱们 ...

  3. 未指定的错误,发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息。数据类型不被支持。

    未指定的错误,发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息.数据类型不被支持. 博客分类: 雅芳生涯 .Net VB C# OracleMicrosoftSecurity  ...

  4. 拓展:switch实现

    拓展:switch实现 参考中谷教育 python视频:switch  switch语句用于编写多分支结构的程序,类似于if ... elif ...else语句.switch语句表达的分支结构比if ...

  5. python描述符descriptor(一)

    Python 描述符是一种创建托管属性的方法.每当一个属性被查询时,一个动作就会发生.这个动作默认是get,set或者delete.不过,有时候某个应用可能会有 更多的需求,需要你设计一些更复杂的动作 ...

  6. protel DXP的类矢量图功能

    一.概述 在写论文的过程中,我们经常需要将protel DXP上的原理图贴入到WORD中.我们可以选择使用截图工具,然后再导入到WORD中.但是由于普通截图图形文件都是位图文件,当我们将图形文件导入W ...

  7. 银联SDK

    最近在开发一个app,需要调用银联的sdk控件,银联提供的demo可以正常运行,但是自己的程序却怎么都编译不通过,到底有哪些需要注意的呢?? 具体的有可能会出现哪些错误我就不列举了,我只是提下有哪些需 ...

  8. sencha touch

    download http://www.sencha.com/products/touch/thank-you/ Developer Center http://developer.sencha.co ...

  9. Jquer学习

    1:什么是Jquery 2:jquery的例子 3:后记

  10. JavaScript闭包底层解析

    1. 闭包是一个函数,这个函数有权访问另一个函数作用域中的变量,创建闭包最常见的方式,就是在函数内部创建函数.要想彻底搞清其中细节,必须从函数从创建到调用的时候都发生了什么入手 2. 函数第一次被调用 ...