(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 ...
随机推荐
- 【转载】C#代码开发过程中如何快速比较两个文件夹中的文件的异同
在日常的使用电脑的过程中,有时候我们需要比较两个文件夹,查找出两个文件夹中不同的文件以及文件中不同的内容信息,进行内容的校对以及合并等操作.其实使用Beyond Compare软件即可轻松比较,Bey ...
- Java开发笔记(二十)一维数组的用法
之前介绍的各类变量都是单独声明的,倘若要求定义相同类型的一组变量,则需定义许多同类型的变量,显然耗时耗力且不宜维护.为此,编程语言引入了数组的概念,每个数组都由一组相同类型的数据构成,对外有统一的数组 ...
- 结合JDK源码看设计模式——享元模式
前言 在说享元模式之前,你一定见到过这样的面试题 public class Test { public static void main(String[] args) { Integer a=Inte ...
- Js与jQuery的相互转换
$()与jQuery() jQuery中$函数,根据传入参数的不同,进行不同的调用,实现不同的功能.返回的是jQuery对象 jQuery这个js库,除了$之外,还提供了另外一个函数:jQuery j ...
- C#中的yield return用法演示源码
下边代码段是关于C#中的yield return用法演示的代码. using System;using System.Collections;using System.Collections.Gene ...
- Android Picasso最详细的使用指南
Picasso 是Square 公司开源的Android 端的图片加载和缓存框架.Square 真是一家良心公司啊,为我们Android开发者贡献了很多优秀的开源项目有木有!像什么Rerefoit . ...
- httpservlet里单纯分页
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletExcep ...
- C#基础第五天
public struct Person { public string _name; public Gender _sex; public int _age; } public enum Gende ...
- 建立第一个SpringBoot小列子(碰到的错误)
当加入@SpringBootApplication注解时,无法得到解析 错误提示:SpringBootApplication cannot be resolved to a type 错误原因是因为s ...
- Mysql数据库基础学习笔记
Mysql数据库基础学习笔记 1.mysql查看当前登录的账户名以及数据库 一.单表查询 1.创建数据库yuzly,创建表fruits 创建表 ) ) ,) NOT NULL,PRIMARY KEY( ...