zoukankan      html  css  js  c++  java
  • Subway poj 2502

    http://poj.org/problem?id=2502

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

    #include<stdio.h>
    #include<vector>
    #include<queue>
    #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;
    int head[maxn], v[maxn];
    double dist[maxn];
    int cnt;
    
    struct node
    {
        int u, v, next;
        double w;
    }maps[maxn];
    
    struct point
    {
        int x,y;
    }s[maxn];
    
    void Add(int u, int v, double w)
    {
        maps[cnt].v = v;
        maps[cnt].w = w;
        maps[cnt].next = head[u];
        head[u] = cnt ++;
    }
    
    double Len(point p , point q, double t)
    {
          return sqrt((p.x-q.x)*(p.x-q.x)*1.0+(p.y-q.y)*(p.y-q.y))/t;
    }
    
    void spfa()
    {
        queue<int>Q;
        Q.push(1);
        v[1]=1;
    
        while(Q.size())
        {
            int p=Q.front();
            Q.pop();
            v[p]=0;
    
            for(int i=head[p]; i!=-1; i=maps[i].next)
            {
                int q=maps[i].v;
    
                if(dist[q]>dist[p]+maps[i].w)
                {
                    dist[q]=dist[p]+maps[i].w;
                    if(!v[q])
                    {
                        v[q]=1;
                        Q.push(q);
                    }
                }
            }
        }
    }
    
    int main()
    {
        int flag = 0;
        scanf("%d %d %d %d",&s[1].x, &s[1].y, &s[2].x, &s[2].y);
    
        int k = 3;
    
        cnt = 0;
        memset(head, -1, sizeof(head));
    
        while(scanf("%d %d", &s[k].x, &s[k].y)!=EOF)
        {
            if(s[k].x != -1)
            {
                if( !flag )
                 flag = 1;
                 else
                 {
                     double sl = Len(s[k], s[k-1], vs);
    
                     Add(k, k-1, sl);
                     Add(k-1, k, sl);
                 }
    
                 k++;
    
            }
            else
                flag = 0;
        }
    
        for(int i=1; i<k; i++)
        {
            for(int j=i+1; j<=k; j++)
            {
                double sl = Len(s[i], s[j], vp);
    
                Add(i, j, sl);
                Add(j, i, sl);
            }
        }
    
        for(int i=1; i<=k; i++)
            dist[i] = oo;
            dist[1] = 0;
    
       spfa();
    
       printf("%.0f
    ", dist[2]);
    
        return 0;
    }
    View Code
  • 相关阅读:
    centOS7 安装docker
    go中json的tag使用
    secureCRT操作redis-cli时, 不断追加ip:port
    golang gorm框架的默认时区问题
    java Date 转mysql timestamp 秒数不一致
    golang sqlx查询时, struct字段冲突
    golang入门time与string转换, time加减时间, 两个时间差
    idea设置每次打开手动选择工作空间
    panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
    Render函数(4):开发可进行排序的表格组件
  • 原文地址:https://www.cnblogs.com/daydayupacm/p/5703620.html
Copyright © 2011-2022 走看看