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. 【递归与分治】 poj 1017

    递归与分治经典例题    要点在于对3*3箱子的讨论 #include <iostream> #include <cstdio> using namespace std; in ...

  2. Centos 6.4下使用VSFTPD无法正常连接与无法上传文件的问题解决

    发表于 2014 年 4 月 13 日 作者 SCKA 最近利用Linux搭建服务器 搭建FTP的时候决定使用VSFTP搭建,结果却出现了无法正常连接与无法上传文件等诸多问题 经过许久的努力,终于让V ...

  3. SEO策略与细节:细节决定成败

    昨天展开seo探讨会.听了一场医疗界seo大神的讲座.收益匪浅今天讲他的演讲内容整理出来与大家分享.希望对医疗界的seo带来些帮助.站长们一起成长! 一.首页 1.元标签设置 标题:上海癫痫病医院哪家 ...

  4. Apache 的常见问题

    Apache "No services installed"问题的处理以及Apache提示 the requested operation has failed而无法启动 安装完 ...

  5. HDU1492/The number of divisors(约数) about Humble Numbers

    题目连接 The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory L ...

  6. Ubuntu + Django + Nginx + uwsgi

    环境 Ubuntu 14.04 Python 2.7 Django 1.8.4 1 安装Nginx     sudo apt-get install nginx 测试  sudo /etc/init. ...

  7. php源码分析之php_info输出中css样式是怎么来的

    我们经常使用echo phpinfo();查看php的配置信息,但是大家知道里面的css样式是怎么来的吗? 我们查看源码(php源码/ext/standard/css.c) PHPAPI void p ...

  8. json optString getString

    optString 和 getString 区别.   optString 当接收到的为空时候  不会报错

  9. PAT (Advanced Level) 1043. Is It a Binary Search Tree (25)

    简单题.构造出二叉搜索树,然后check一下. #include<stdio.h> #include<algorithm> using namespace std; +; st ...

  10. BootStrap中关于input-group的问题(未解决)

    ****************************************2016年1月6日 23:08******************************* 本来想实现的如下功能: 但 ...