#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. dotMemory 2019.3.1一直试用

    创建一个bat脚本, 里面写上: reg delete HKEY_CURRENT_USER\Software\JetBrains\dotMemory /freg delete HKEY_CURRENT ...

  2. c++输入输出,保留几位小数

    #include <iomanip> //头文件 //第一种写法 cout<<setiosflags(ios::); //第二种写法 cout.setf(ios::fixed) ...

  3. <Wonder Woman> 摘抄

    <Wonder Woman> My father told me once, he said,“ If you see something wrong happening in the w ...

  4. C#连接数据库的方法

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  5. HTML连载66-过度模块的连写、弹性效果

    一.过渡模块的连写 1.过渡连写格式: 过渡属性  过渡时长  运动速度  延迟时间: 2.过渡连写注意点: (1)和分开写一样,如果想要多个属性添加过渡效果,也是使用逗号来隔开即可. (2)连写的时 ...

  6. Android 调试桥 (adb) 是 命令行命令--官方拷贝过来的,留作自己查看

    Android 调试桥 (adb) 是一种功能多样的命令行工具,可让您与设备进行通信.adb 命令便于执行各种设备操作(例如安装和调试应用),并提供对 Unix shell(可用来在设备上运行各种命令 ...

  7. 使用UCSC Genome Browser下载人类所有mRNA序列

    打开UCSC Genome Browser官网.网址:http://genome.ucsc.edu/ 点击导航栏的Genome Data 在新的页面中,点击human,可快速定位至页面中人类基因组数据 ...

  8. WAF的基础绕过

    方法分类: 1.HTTP参数污染绕过 2.HTTP Header头部欺骗绕过 3.HTTP参数溢出绕过 4.HTTP分块传输绕过 5.HTTP数据编码绕过 6.HTTP Pipline绕过(Keep- ...

  9. luogu P3384 【模板】重链剖分

    参考https://www.cnblogs.com/wushengyang/p/10808505.html,感谢 #include<iostream> #include<algori ...

  10. [更新ing]zzy的家里蹲网课日记

    前言 精神小(ge)伙(zi)终于记起了他的博客密码...... 寒假以来,积累了巨多的好想法想要写博客,往往都是因为各种原因半途而废--在学习生活上甚至也有各种拖延的毛病:爱欠作业不早睡,不见成绩不 ...