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. 【转】RestQL:现代化的 API 开发方式

    原文:http://tech.meituan.com/koa-restql.html RestQL:现代化的 API 开发方式 李鑫 ·2016-08-12 11:26 koa-restql 已经在  ...

  2. eclipse无法导入已有android项目

    问题: 今天发现我拷贝的一个android项目无法导入到eclipse,但是其它的已有android项目却可以导入 思路 现在网络这么流行,当然是上网查,得益于eclipse无法导入Android工程 ...

  3. AU3脚本 记录

    编译程序使用自定义图标: #AutoIt3Wrapper_Icon=自定义图标地址 打开指定的网址:(也可以指定其他浏览器exe) Run(@ProgramFilesDir & "\ ...

  4. Android Camera(二)

    上次已经写过SurfaceView显示Camera摄像了,代码可以运行,但是里面有问题,这次纠正过来,顺便实现变焦: 代码: public class CameravedioActivity exte ...

  5. Lucene中的合并因子mergeFactor

    mergeFactor 是用来决定segment该如何被addDocument()方法进行合并的. 当mergeFactor取比较小的值时,索引时所使用的内存较少 而且搜素未优化的速度会比较快.因此, ...

  6. AS3条件编译

    package { import flash.display.Sprite; public class Main extends Sprite { public function Main() { s ...

  7. asp 正则替换函数

    Function RegExpTest(patrn,str1,strng) Dim regEx',str1 ' 建立变量 'str1 = "The quick brown fox jumpe ...

  8. 迄今最安全的MySQL?细数5.7那些惊艳与鸡肋的新特性(上)【转载】

    转自: DBAplus社群 http://www.toutiao.com/m5762164771/ 迄今最安全的MySQL?细数5.7那些惊艳与鸡肋的新特性(上) - 今日头条(TouTiao.com ...

  9. 打开jsp页面自动加载多个Action的实现方法

    平时我们加载Action的时候都是提交表单,或者点击按钮以后才能发起Action请求. 现在我要实现一个功能:打开一个网站的首页从数据库中立刻读取多条不同表中的数据显示在页面上.这个时候要发起多个Ac ...

  10. Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconn

    使用MySQL执行update的时候报错:   MySQL     在使用mysql执行update的时候,如果不是用主键当where语句,会报如下错误,使用主键用于where语句中正常. 异常内容: ...