题意:在一个城市里,分布着若干条地铁线路,每条地铁线路有若干个站点,所有地铁的速度均为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. MSSQL批量替换网址字符串语句

    1.如何批量替换ntext字段里面的数据 问题描述: 我想把数据库中News表中的字段content中的一些字符批量替换. 我的content字段是ntext类型的. 我想替换的字段是content字 ...

  2. C#中的Dictionary简介

    简介在C#中,Dictionary提供快速的基于兼职的元素查找.当你有很多元素的时候可以使用它.它包含在System.Collections.Generic名空间中. 在使用前,你必须声明它的键类型和 ...

  3. ajax xmlhttp下open方法POST、GET参数的区别

    1. get是从服务器上获取数据(会暴露客户端ip),post是向服务器传送数据.2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看 ...

  4. 解决UITableViewCell左侧分割线有空白的问题

    ios7中,UITableViewCell左侧会有默认15像素的空白.设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉. ios8中,setSeparatorIn ...

  5. 10集合:List<T>,Dictionary<K,V>

    List<T>泛型集合 List<T>是C#中一种快捷.易于使用的泛型集合类型,使用泛型编程为编写面向对象程序增加了极大的效率和灵活性.   1.List<T>用法 ...

  6. 解决js浮点数计算bug

    1.加 function add(a, b) { var c, d, e; try { c = a.toString().split(".")[1].length; } catch ...

  7. Javascript 类数组(Array-like)对象

    Javascript中的类数组对象(Array-like object)指的是一些看起来像数组但又不是数组的对象.Javascript中的arguments变量.document.getElement ...

  8. [jQuery编程挑战]006 生成一个倒计时效果

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="utf-8&quo ...

  9. openerp 中如何方便对搜索时间段

    以前为了方便的搜索时间区间,经常用wizard对方式,设置开始  结束时间,需要做大量对代码工作, 今天看了search view对组成, 可以用2个filter_domain 来做, 这样用户需要输 ...

  10. Unix/Linux 'dirctory tree' command.

    ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' It se ...