Description

  You 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.
 
  这个题目是最短路问题,建边的话就是地铁线上的是直线距离除以车的速度,其他的话是除以走的速度,是一个完全图。。。
 
代码如下:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int INF=10e8; bool vis[]; void Dijkstra(double lowcost[],double cost[][],int N,int start)
{
for(int i=;i<=N;++i)
{
lowcost[i]=INF;
vis[i]=;
}
lowcost[start]=; int k;
double minn; for(int cas=;cas<=N;++cas)
{
minn=INF;
k=-; for(int i=;i<=N;++i)
if(!vis[i] && minn>lowcost[i])
{
minn=lowcost[i];
k=i;
} if(k==-)
return; vis[k]=; for(int i=;i<=N;++i)
if(!vis[i] && cost[k][i]>= && lowcost[i]>lowcost[k]+cost[k][i])
lowcost[i]=lowcost[k]+cost[k][i];
}
} int X[],Y[];
int N;
double map1[][];
double ans[]; double getdis(int a,int b)
{
return sqrt((double(X[a]-X[b]))*(X[a]-X[b])+(double(Y[a]-Y[b]))*(Y[a]-Y[b]));
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); for(int i=;i<=;++i)
for(int j=;j<=;++j)
map1[i][j]=-; scanf("%d %d %d %d",&X[],&Y[],&X[],&Y[]); N=;
int base; while(~scanf("%d %d",&X[N],&Y[N]))
{
base=N;
while(X[N]!=- || Y[N]!=-)
{
++N;
scanf("%d %d",&X[N],&Y[N]);
} for(int i=base;i<N-;++i)
map1[i][i+]=map1[i+][i]=3.0*getdis(i,i+)/2000.0;
}
--N; for(int i=;i<=N;++i)
for(int j=;j<=i;++j)
if(map1[i][j]<)
map1[i][j]=map1[j][i]=3.0*getdis(i,j)/500.0; Dijkstra(ans,map1,N,); printf("%d\n",(int)(ans[]+0.5)); return ;
}

(简单) POJ 2502 Subway,Dijkstra。的更多相关文章

  1. POJ 2502 - Subway Dijkstra堆优化试水

    做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...

  2. POJ 2502 Subway (Dijkstra 最短+建设规划)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6689   Accepted: 2176 Descriptio ...

  3. 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 ...

  4. Dijkstra+计算几何 POJ 2502 Subway

    题目传送门 题意:列车上行驶40, 其余走路速度10.问从家到学校的最短时间 分析:关键是建图:相邻站点的速度是40,否则都可以走路10的速度.读入数据也很变态. #include <cstdi ...

  5. poj 2502 Subway【Dijkstra】

    <题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...

  6. POJ 2502 Subway(迪杰斯特拉)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6692   Accepted: 2177 Descriptio ...

  7. POJ 2502 Subway

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4928   Accepted: 1602 Descriptio ...

  8. POJ 2502 Subway (最短路)

    Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...

  9. POJ 2502 Subway ( 最短路 && 最短路建图 )

    题意 : 给出二维平面上的两个点代表起点以及终点,接下来给出若干条地铁线路,除了在地铁线路上行进的速度为 40km/h 其余的点到点间都只能用过步行且其速度为 10km/h ,现问你从起点到终点的最短 ...

随机推荐

  1. sql server 的datediff函数

    这两天要把一个sqlserver数据库的程序改成oracle的,发现两个数据库之间的函数很多不一样.sqlserver的数据库中的DateDiff 函数用法解释如下: 描述 返回两个日期之间的时间间隔 ...

  2. JS-加载页面的时候自动选择刚才所选择option

    <body class="no-skin" onload="option_auto(${pd.PACK_SORT})"> <select na ...

  3. 百度,google的地理编码

    1.百度的地理编码:(不支持中国以外的其它城市) http://api.map.baidu.com/geocoder/v2/?ak=E974997f80db18330f8f5c61d084a677&a ...

  4. js、html中的单引号、双引号及其转义使用

    js.html中的单引号.双引号及其转义使用在js中对相关字符做判断或取值的时候很多情况下都会用到这些. ------ 在一个网页中的按钮,写onclick事件的处理代码,不小心写成如下:<in ...

  5. Android OpenGL ES(三)OpenGL ES API 命名习惯 .

    OpenGL ES是个跨平台的3D图形开发包规范,最常见的实现是采用C语言实现的,Android OpenGL ES 实现上是使用Java 语言对底层的C接口进行了封装,因此在android.open ...

  6. execlp("ls","flw","-?",(char *)0) 为什么少了最后的一个参数就不行?

    execlp("ls","flw","-?",(char *)0) 为什么少了最后的一个参数就不行?

  7. 浅谈C# 多态的魅力(虚方法,抽象,接口实现)

    前言:我们都知道面向对象的三大特性:封装,继承,多态.封装和继承对于初学者而言比较好理解,但要理解多态,尤其是深入理解,初学者往往存在有很多困惑,为什么这样就可以?有时候感觉很不可思议,由此,面向对象 ...

  8. CC_CALLBACK之间的区别

    #define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_A ...

  9. HDU - 4994 Revenge of Nim (取石子游戏)

    Problem Description Nim is a mathematical game of strategy in which two players take turns removing ...

  10. HTML5来了:5个好用的混合式App开发工具

    在残酷的移动互联网竞争环境下, HTML5技术一直受到各方关注,“HTML5颠覆原生 App”的争论也从未停止过,不管怎样HTML5生态的构建方兴未艾.不过对于移动开发者来说更关心的问题是如何低成本. ...