#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
const int N=;
const double INF=0x3f3f3f3f;
int k,l;
struct node
{
double x,y;
int num;
} s[N];
bool st[N];
double dist[N];
void spfa(int x)
{
memset(st,false,sizeof st );
for(int i=;i<N;i++)
dist[i]=INF;
st[x]=true;
dist[x]=;
queue<int>q;
while(!q.empty())
q.pop();
q.push(x);
while(!q.empty())
{
int u=q.front();
st[u]=false;
q.pop();
for(int i=; i<=k; i++)
{
if(i==u)
continue;
double far,t;
far=sqrt(((s[u].y-s[i].y)*(s[u].y-s[i].y))+((s[u].x-s[i].x)*(s[u].x-s[i].x)));
far=far/1000.0;
if(fabs(s[u].num-s[i].num)==)
t=far/40.0;
else
t=far/10.0;
if(dist[i]>dist[u]+t)
{
dist[i]=dist[u]+t;
if(!st[i])
{
st[i]=true;
q.push(i);
}
}
}
}
}
int main()
{
double s1,s2,e1,e2;
double x,y;
k=,l=;
cin>>s1>>s2>>e1>>e2;
//只有相邻的站点能到
while(cin>>x>>y)
{
if(x==-&&y==-)
{
if(l==)
break;
l++;
continue;
}
s[k].x=x,s[k].y=y;
s[k++].num=l++;
}
s[].x=s1,s[].y=s2,s[].num=-;
s[k].x=e1,s[k].y=e2,s[k].num=-;
spfa();
//四舍五入
cout<<(int)(dist[k]*+0.5)<<endl;
return ;
}

Subway POJ - 2502 spfa的更多相关文章

  1. Subway POJ 2502

    题目链接: http://poj.org/problem?id=2502 题目大意: 你刚从一个安静的小镇搬到一个吵闹的大城市,所以你不能再骑自行车去上学了,只能乘坐地铁或者步行去上学.因为你不想迟到 ...

  2. L - Subway - POJ 2502

    题意:在一个城市里,分布着若干条地铁线路,每条地铁线路有若干个站点,所有地铁的速度均为40km/h.现在你知道了出发地和终点的坐标,以及这些地铁 线路每个站点的坐标,你的步行速度为10km/h,且你到 ...

  3. Subway POJ - 2502 最短路

    题意:给出地铁线  起点和 终点  坐地铁速度为v2  走路为v1 求起点到终点的最短距离  (答案需要四舍五入这里坑了好久) 拿给出的地铁站点 和起点终点建边即可  然后跑个迪杰斯特拉 #inclu ...

  4. 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 ...

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

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

  6. L - Subway(最短路spfa)

    L - Subway(最短路spfa) You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. In ...

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

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

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

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

  9. POJ 2502 Subway

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

随机推荐

  1. nCompass-网络流量基础知识

    nCompass-网络流量基础知识 1.  流量分析基础知识 1.1  常见的流量分析方式: SNMP: 网管平台通过主动式获取设备接口流量信息. Flow:网络设备将穿越的数据流信息精简压缩打包. ...

  2. 关于软件 TELEGRAM(电报) 的说明

    PLUS是TELEGRAM(电报)的三方客户端. 而 电报 是一款即时通讯软件.功能全面,安全性好,但在国内无法直接访问. 相关安全性介绍请看这里:https://www.anquanke.com/p ...

  3. [MongoDB] 使用PHP根据_id字段查询数据

    mongo中的_id是一个objectid对象类型,不管是查询时作为条件,还是列表时展示内容,都需要进行一下抓换 查询时要转为objectid对象 列表时要把对象转成字符串覆盖回_id字段 $filt ...

  4. SAP VL10B 报错 - 4500000317 000010 交付 $ 1 的交付项目 000010 与 POD 无关-

    SAP VL10B 报错 - 4500000317 000010 交付 $ 1 的交付项目 000010 与 POD 无关- 如下公司间STO单据, 业务背景是货物从公司代码LYSP转入公司代码BTS ...

  5. docker jenkins 前端node项目 自动化部署异常 env: ‘node’: No such file or directory

    出现问题是docker jenkins 里面没有自动安装node导致找不到这个Node命令 解决方案:手动安装nodejs # 进入jenkins对应容器中 # docker exec -it [对应 ...

  6. jenkin docker node 自动化部署配置

    jenkins 安装必须插件 NodeJS Plugin Publish Over SSH 1:新建一个任务,选择构建一个自由风格的软件项目 2:源码管理选择Git 2.1 填写Git项目地址Repo ...

  7. 第10章 DOM

    第10章 DOM 10.1 节点层次 10.1.1 Node 类型 10.1.2 Document 类型 10.1.3 Element 类型 10.1.4 Text 类型 10.1.5 Comment ...

  8. RestTemplate + okhttp 实现远程调用

    1. 添加依赖 <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp --> <dependency ...

  9. 避免js重复加载的问题

    避免js重复加载的问题 在日常开发中,一个页面加载另一个页面的时候,就会把另一个页面的js也会加载进来,那么如何才能避免被加载页面不再重复加载已经加载过的js呢? 先上代码 动态加载js // 加载j ...

  10. HDU-1166 敌兵布阵 (树状数组模板题——单点更新,区间求和)

    题目链接 AC代码: #include<iostream> #include<cstdio> #include<cstring> #include<algor ...