题意:在一个城市里,分布着若干条地铁线路,每条地铁线路有若干个站点,所有地铁的速度均为40km/h。现在你知道了出发地和终点的坐标,以及这些地铁 线路每个站点的坐标,你的步行速度为10km/h,且你到了地铁的任意一个站之后就刚好有地铁出发。问你从出发点到终点最少需要多少时间。

//////////////////////////////////////////////////////////////////////

有很多站点,给的数据只是一条条线路,所以需要先预处理数据,增加任意两点人走需要的时间。数据预先处理比较麻烦......
#include<stdio.h>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std; const int maxn = 100005;
const int oo = 0xfffffff;
const double vs = 40*1000/60.0;//每分钟走多少米
const double vp = 10*1000/60.0; struct node
{
    int u, v, next;
    double c;//两点之间所需时间
}e[maxn];
struct point
{
    int x, y;
}p[1005]; int nPoint, head[1005];
double dis[1005];
bool vis[1005]; double Len(point a, point b, double v)
{
    return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ) / v;
}
void Add(int u, int v, double len, int k)
{
    e[k].u = u;
    e[k].v = v;
    e[k].c = len;
    e[k].next = head[u];
    head[u] = k;
}
void spfa()
{
    stack<int> sta;
    sta.push(1);     while(sta.size())
    {
        int i = sta.top();sta.pop();
        vis[i] = false;         for(int j=head[i]; j!=0; j=e[j].next)
        {
            int u = e[j].u, v = e[j].v;
            double c = e[j].c;             if(dis[u]+c < dis[v])
            {
                dis[v] = dis[u] + c;
                if(vis[v] == false)
                {
                    vis[v] = true;
                    sta.push(v);
                }
            }
        }
    }
} int main()
{
    int i, j, flag=0, k=1;     scanf("%d%d%d%d", &p[1].x, &p[1].y, &p[2].x, &p[2].y);     nPoint = 3;
    while(scanf("%d%d", &p[nPoint].x, &p[nPoint].y) != EOF)
    {
        if(p[nPoint].x != -1)
        {
            if(flag == 0)
                flag = 1;
            else
            {
                double c = Len(p[nPoint], p[nPoint-1], vs);
                Add(nPoint, nPoint-1, c, k++);
                Add(nPoint-1, nPoint, c, k++);
            }             nPoint++;
        }
        else
            flag = 0;
    }     for(i=1; i<nPoint; i++)
    for(j=i+1; j<=nPoint; j++)
    {
        double c = Len(p[i], p[j], vp);
        Add(i, j, c, k++);
        Add(j, i, c, k++);
    }     for(i=2; i<nPoint; i++)
        dis[i] = oo;     spfa();     printf("%.0f\n", dis[2]);     return 0;
}

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

  1. Subway POJ 2502

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

  2. Subway POJ - 2502 spfa

    #include<cstdio> #include<cmath> #include<cstring> #include<cstring> #includ ...

  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 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...

随机推荐

  1. 用java写bp神经网络(三)

    孔子曰,吾日三省吾身.我们如果跟程序打交道,除了一日三省吾身外,还要三日一省吾代码.看代码是否可以更简洁,更易懂,更容易扩展,更通用,算法是否可以再优化,结构是否可以再往上抽象.代码在不断的重构过程中 ...

  2. iOS开发UI篇——Button基础

    一.简单说明 一般情况下,点击某个控件后,会做出相应反应的都是按钮 按钮的功能比较多,既能显示文字,又能显示图片,还能随时调整内部图片和文字的位置 二.按钮的三种状态 1. normal(普通状态) ...

  3. Sqoop import加载HBase案例详解

    简单写一下如何将订单表sqoop到hbase表中的步骤. 下表: 1.通过hbase shell 打开hbase. 2.创建一个hbase表 create 'so','o' 3.将so表的数据导入到h ...

  4. ThinkPHP框架下,给jq动态添加的标签添加点击事件移除标签

    jq移除标签主要就是$("#要移除的id").remove();不再赘述,这里要提醒的是jq中动态添加标签后怎样添加点击事件.一般的jq添加点击事件是用这种方法$("#i ...

  5. 测试通过Word直接发布博文

    这里是来自word 2013的一篇测试文章. 测试直接通过Word自带的bloger功能发布博客文章. 这里插入一张图片

  6. 如何编写一个简单的makefile

    一个规则的构成 目标:依赖1,依赖2······ 命令 例子: objs := init.o nand.o head.o main.o nand.bin : $(objs) arm-linux-ld ...

  7. Zephyr-MQTT

    Zephyr OS 支持MQTT协议,其源码目录在: # cd /zephyr-/samples/net/paho_mqtt_clients/publisher/ # cd /zephyr-1.5.0 ...

  8. LeapMotion预览——什么是LeapMotion

    LeapMotion预览 这个就是LeapMotion: 原文转自:   LeapMotion预览 LeapMotion 官网:http://leapmotion.com/ 开发者:https://d ...

  9. Node.js教程

    Node.js是什么? Node.js是建立在谷歌Chrome的JavaScript引擎(V8引擎)的服务器端平台.Node.js是由瑞恩·达尔在2009年开发的,它的最新版本是v0.10.36. N ...

  10. [转]Windows Azure上安装SharePoint 2013

    基于Windows Azure 安装SharePoint 2013 前段时间写的基于Windows Azure安装SharePoint系列,由于Azure的体验账号过期了,所以不得不暂停.今天有幸参加 ...