(poj 2502) Subway 最短路
题目链接:
题意:在一个城市里有许多地铁,现在你知道每条地铁的起点 终点与停站点的坐标,知道我们的起始坐标与终点坐标,问加上走路最快到达终点的时间是多少?
方法:求出任意两点的车速时间与步行时间,再算出最短路
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define met(a,b) memset(a,b,sizeof(a))
#define N 100010
#define vs 40*1000/60.0 车速
#define vp 10*1000/60.0 人速
struct point
{
int x,y; }P[];
struct node
{
int v,u,next;
double l;
}s[N];
int a[],vis[],npoint;
double dis[];
double len(point a,point b,double v)
{
return sqrt((b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x))/v;
}
void add(int u,int v,double l,int k)
{
s[k].l=l;
s[k].v=v;
s[k].next=a[u];
a[u]=k;
}
void spfa()
{
met(vis,);
queue<int >Q;
Q.push();
vis[]=;
while(Q.size())
{
int u=Q.front();
Q.pop();
vis[u]=;
for(int i=a[u];i!=-;i=s[i].next)
{
int v=s[i].v;
if(dis[v]>dis[u]+s[i].l)
{
dis[v]=dis[u]+s[i].l;
if(!vis[v])
{
vis[v]=;
Q.push(v);
}
}
}
}
}
int main()
{
int k,flag=;
scanf("%d %d %d %d",&P[].x,&P[].y,&P[].x,&P[].y);
int npoint=;
met(a,-);k=;
while(scanf("%d %d",&P[npoint].x,&P[npoint].y)!=EOF)
{
if(P[npoint].x!=-)
{
if(flag==)
flag=;
else
{
double c=len(P[npoint],P[npoint-],vs);
add(npoint,npoint-,c,k++);
add(npoint-,npoint,c,k++);
}
npoint++;
}
else
flag=;
}
for(int i=;i<npoint;i++)
{
for(int j=i+;j<=npoint;j++)
{
double c=len(P[i],P[j],vp);
add(i,j,c,k++);
add(j,i,c,k++);
}
}
for(int i=;i<npoint;i++)
dis[i]=INF;
spfa();
printf("%.0f\n",dis[]);
return ;
}
(poj 2502) Subway 最短路的更多相关文章
- POJ 2502 Subway ( 最短路 && 最短路建图 )
题意 : 给出二维平面上的两个点代表起点以及终点,接下来给出若干条地铁线路,除了在地铁线路上行进的速度为 40km/h 其余的点到点间都只能用过步行且其速度为 10km/h ,现问你从起点到终点的最短 ...
- 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 ...
- POJ 2502 - Subway Dijkstra堆优化试水
做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...
- POJ 2502 Subway (最短路)
Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...
- POJ 2502 Subway(迪杰斯特拉)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6692 Accepted: 2177 Descriptio ...
- POJ 2502 Subway (Dijkstra 最短+建设规划)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6689 Accepted: 2176 Descriptio ...
- POJ 2502 Subway
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4928 Accepted: 1602 Descriptio ...
- (简单) POJ 2502 Subway,Dijkstra。
Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of ...
- Dijkstra+计算几何 POJ 2502 Subway
题目传送门 题意:列车上行驶40, 其余走路速度10.问从家到学校的最短时间 分析:关键是建图:相邻站点的速度是40,否则都可以走路10的速度.读入数据也很变态. #include <cstdi ...
- POJ 2502 Subway dij
这个题的输入输出注意一下就好 #include<cstdio> #include<cstring> #include<queue> #include<cstd ...
随机推荐
- Redux进阶(像VUEX一样使用Redux)
更好的阅度体验 前言 redux的问题 方案目标 如何实现 思考 前言 Redux是一个非常实用的状态管理库,对于大多数使用React库的开发者来说,Redux都是会接触到的.在使用Redux享受其带 ...
- Java中float型最大值大于long型?
float型在内存中占用的是4个字节的空间,而long型占用的是8个字节的空间. 注:float类型的范围是:一3.403E38~3.403E38.而long类型的范围是:-2^63~2^63-1(大 ...
- 常用的Arrays类和二维数组以及二分法的介绍
---恢复内容开始--- 1.Array类 Array中包含了许多数组的常用操作,较为常见的有: (1)快速输出 import java.util.Arrays; public class Test{ ...
- Maven(十二)Maven 依赖详解
依赖的传递性 注意1:在Eclipise创建的Maven项目,若依赖eclipse空间中其他自己创建的 的项目时,此时并不会报错,但是当执行mvn compile命令时还是会显示缺失败.所以依赖的其他 ...
- Linux平台安装MongoDB及使用Docker安装MongoDB
一.Linux平台安装MongoDB MongoDB 提供了 linux 各发行版本 64 位的安装包,你可以在官网下载安装包. 下载地址:https://www.mongodb.com/downlo ...
- C# 定时器-System.Timers.Timer
using Newtonsoft.Json; using Rafy; using Rafy.Domain; using System; using System.Collections.Generic ...
- 基本数据类型 int float str
一.数字型1.整型 int======================================基本使用======================================1.用途 用来 ...
- vis.js 4.21.0 Timeline localization
from:http://visjs.org/timeline_examples.html https://github.com/almende/vis https://github.com/momen ...
- java 线程方法 ---- yiled()
class MyThread3 implements Runnable{ @Override public void run() { for (int i = 0; i < 3; i++){ / ...
- iOS----------使用cocoapods遇到的问题
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad ...