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. Office 365 开发概览系列文章和教程

    Office 365 开发概览系列文章和教程 原文于2017年2月26日首发于LinkedIn,请参考链接 引子 之前我在Office 365技术社群(O萌)中跟大家提到,3月初适逢Visual St ...

  2. ps人物像发丝的抠图处理

    1-复制图层——使用快速选择工具——添加选区(包含发丝)——调整边缘 2- 提高半径(尽量高)——降低移动边缘——输出到新建图层 这个时候,我们发现人物的很多地方是透明的,不用担心,因为我们这一步先是 ...

  3. LBPL--基于Asp.net、 quartz.net 快速开发定时服务的插件化项目

    LBPL 这一个基于Asp.net. quartz.net 快速开发定时服务的插件化项目 由于在实际项目开发中需要做定时服务的操作,大体上可以理解为:需要动态化监控定时任务的调度系统. 为了实现快速开 ...

  4. BZOJ4403 序列统计—Lucas你好

    绝对是全网写的最详细的一篇题解  题目:序列统计 代码难度:简单 思维难度:提高+-省选 讲下题面:给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案 ...

  5. Redhat

    vm1 port:192.168.210.102 user:root;pwd:123456 user:openflowpwd:openflowKkm09!q esx4.1 server 安装一.修改I ...

  6. [译]Selenium Python文档:八、附录:FAQ常见问题

    另外一个FAQ:https://github.com/SeleniumHQ/selenium/wiki/Frequently-Asked-Questions 8.1.怎样使用ChromeDriver ...

  7. JS Math.round()方法原理

    请先测试代码: <!doctype html> <html lang="en"> <head> <meta charset="U ...

  8. 提交任务到Spark

    1.场景 在搭建好Hadoop+Spark环境后,现准备在此环境上提交简单的任务到Spark进行计算并输出结果.搭建过程:http://www.cnblogs.com/zengxiaoliang/p/ ...

  9. spring(二) AOP之AspectJ框架的使用

    前面讲解了spring的特性之一,IOC(控制反转),因为有了IOC,所以我们都不需要自己new对象了,想要什么,spring就给什么.而今天要学习spring的第二个重点,AOP.一篇讲解不完,所以 ...

  10. 解决Highcharts 5.0.7,IE8下bar类型图表无法显示的问题

    引用如上, 当图标类型为bar时,IE8无法直接显示, 官网也一样, 但通过切换图例可以显示, 所以加入以下代码解决此问题 未经允许,严禁转载!!!