have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want to be late for class, you want to know how long it will take you to get to school.
You walk at a speed of 10 km/h. The subway travels at 40 km/h. Assume that you are lucky, and whenever you arrive at a subway station, a train is there that you can board immediately. You may get on and off the subway any number of times, and you may switch between different subway lines if you wish. All subway lines go in both directions.Input

Input consists of the x,y coordinates of your home and your school, followed by specifications of several subway lines. Each subway line consists of the non-negative integer x,y coordinates of each stop on the line, in order. You may assume the subway runs in a straight line between adjacent stops, and the coordinates represent an integral number of metres. Each line has at least two stops. The end of each subway line is followed by the dummy coordinate pair -1,-1. In total there are at most 200 subway stops in the city.

Output

Output is the number of minutes it will take you to get to school, rounded to the nearest minute, taking the fastest route.

Sample Input

0 0 10000 1000
0 200 5000 200 7000 200 -1 -1
2000 600 5000 600 10000 600 -1 -1

Sample Output

21

此题没输出,真是蛋疼,错了也不知道怎么改,最后还是参考得来,因为范围问题错了n次,最关键的地方就是储存图!!!
处理时很要注重细节
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const double inf=1e30;
double d[300],cost[300][300];
int n=2;
struct node{
   double x,y;
}e[300];
double dis(node a,node b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void dijkstra()
{
    queue<int>Q;
    bool vis[300];
    for(int i=0;i<n;i++)
    {
        d[i]=inf;
        vis[i]=0;
    }
    d[0]=0;
    Q.push(0);
    vis[0]=1;
    while(!Q.empty()){
        int a=Q.front();
        Q.pop();
        vis[a]=0;
        for(int i=0;i<n;i++)
            if(d[i]>d[a]+cost[a][i])
            {
                d[i]=d[a]+cost[a][i];
                if(!vis[i])
                {
                    vis[i]=1;
                    Q.push(i);
                }
            }
    }
}
int main()
{
    scanf("%lf%lf%lf%lf",&e[0].x,&e[0].y,&e[1].x,&e[1].y);
    for(int i=0;i<300;i++)
        for(int j=0;j<300;j++)
        {
            if(i==j)cost[i][j]=0;
            else cost[i][j]=inf;
        }
    double a,b;
    while(~scanf("%lf%lf",&a,&b)){
            int m=n;
            while(1){
                if(a==-1&&b==-1)break;
                e[n++]={a,b};
                scanf("%lf%lf",&a,&b);
            }
        for(int i=m+1;i<n;i++)
        {
            cost[i][i-1]=cost[i-1][i]=dis(e[i],e[i-1])*3.0/2000;
        }
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cost[i][j]=min(cost[i][j],dis(e[i],e[j])*6.0/1000);
    dijkstra();
    printf("%.0f\n",d[1]);
    return 0;
}

poj2502最短路!的更多相关文章

  1. poj2502 最短路

    //Accepted 504 KB 16 ms //spfa最短路 //把n个地铁站作为n个顶点,边权为从一个站到另一个站的时间 //注意:地铁在相邻的两站之间是直线行驶,但其他的就不是了 #incl ...

  2. POJ-2502(Dijikstra应用+最短路)

    Subway POJ-2502 这里除了直接相连的地铁站,其他图上所有的点都要连线,这里是走路的速度. 记住最后的结果需要四舍五入,否则出错. #include<iostream> #in ...

  3. POJ2502:Subway(最短路)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14634   Accepted: 4718 题目链接:http ...

  4. POJ-2502 Subway( 最短路 )

    题目链接:http://poj.org/problem?id=2502 Description You have just moved from a quiet Waterloo neighbourh ...

  5. bzoj1001--最大流转最短路

    http://www.lydsy.com/JudgeOnline/problem.php?id=1001 思路:这应该算是经典的最大流求最小割吧.不过题目中n,m<=1000,用最大流会TLE, ...

  6. 【USACO 3.2】Sweet Butter(最短路)

    题意 一个联通图里给定若干个点,求他们到某点距离之和的最小值. 题解 枚举到的某点,然后优先队列优化的dijkstra求最短路,把给定的点到其的最短路加起来,更新最小值.复杂度是\(O(NElogE) ...

  7. Sicily 1031: Campus (最短路)

    这是一道典型的最短路问题,直接用Dijkstra算法便可求解,主要是需要考虑输入的点是不是在已给出的地图中,具体看代码 #include<bits/stdc++.h> #define MA ...

  8. 最短路(Floyd)

    关于最短的先记下了 Floyd算法: 1.比较精简准确的关于Floyd思想的表达:从任意节点A到任意节点B的最短路径不外乎2种可能,1是直接从A到B,2是从A经过若干个节点X到B.所以,我们假设maz ...

  9. bzoj1266最短路+最小割

    本来写了spfa wa了 看到网上有人写Floyd过了 表示不开心 ̄へ ̄ 改成Floyd试试... 还是wa ヾ(。`Д´。)原来是建图错了(样例怎么过的) 结果T了 于是把Floyd改回spfa 还 ...

随机推荐

  1. [LeetCode] Trapping Rain Water II 题解

    题意 题目 思路 我一开始想的时候只考虑到一个结点周围的边界的情况,并没有考虑到边界的高度其实影响到所有的结点盛水的高度. 我们可以发现,中间是否能够盛水取决于边界是否足够高于里面的高度,所以这必然是 ...

  2. linux vi hjkl由来

    很远原因来自历史 I was reading about vim the other day and found out why it used hjkl keys as arrow keys. Wh ...

  3. Spring中一个类的注入和引用是不一样的

    1.在Spring管理下的bean需要以下面这种方式引入(一种注入方式): private MgrService mgrService; public MgrService getMgrService ...

  4. iOS开发之触摸事件及手势

    1.iOS中的事件 在用户使用app过程中,会产生各种各样的事件,iOS中的事件可以分为3大类型: 2.响应者对象 在iOS中不是任何对象都能处理事件,只有继承了UIResponder的对象才能接收并 ...

  5. UIImageView帧动画相关属性和方法

    @property(nonatomic,copy) NSArray *animationImages; 需要播放的序列帧图片数组(里面都是UIImage对象,会按顺序显示里面的图片) @propert ...

  6. oracle学习 笔记(1)

    题记:之前用的是SQL server数据库,现因需求使用Oracle数据库,写此博客来记录学习: 一.表空间管理.用户管理.给用户授权 1.在Oracle中每创建数据库会在系统服务中多一个数据库实例, ...

  7. Tomcat 优化和性能监测

    1. JVM 优化(Tomcat 启动行参数) Linux 修改 catalin.sh Windows 修改 catalin.bat   Linux系统中tomcat的启动参数 export JAVA ...

  8. linux最小安装

    (1)系统安装类型选择及自定义额外包组 进入如图2-28所示界面.上半部分是系统定制的不同的系统安装类型选择项,默认是“Desktop”,这里我们选择“Minimal”,即最小化安装,下半部分是在上面 ...

  9. Modbus通信协议详解

    附:http://www.360doc.com/content/14/0214/13/15800361_352436989.shtml 一.Modbus 协议简介 Modbus 协议是应用于电子控制器 ...

  10. 创建keystone的catalog时提示:‘Internal Server Error (HTTP 500)’

    在生成keystone的catalog时: [root@controller ~]# openstack service create --name keystone --description &q ...