(简单) POJ 2502 Subway,Dijkstra。
Description
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。的更多相关文章
- POJ 2502 - Subway Dijkstra堆优化试水
做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...
- POJ 2502 Subway (Dijkstra 最短+建设规划)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6689 Accepted: 2176 Descriptio ...
- 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 ...
- Dijkstra+计算几何 POJ 2502 Subway
题目传送门 题意:列车上行驶40, 其余走路速度10.问从家到学校的最短时间 分析:关键是建图:相邻站点的速度是40,否则都可以走路10的速度.读入数据也很变态. #include <cstdi ...
- poj 2502 Subway【Dijkstra】
<题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...
- POJ 2502 Subway(迪杰斯特拉)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6692 Accepted: 2177 Descriptio ...
- POJ 2502 Subway
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4928 Accepted: 1602 Descriptio ...
- POJ 2502 Subway (最短路)
Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...
- POJ 2502 Subway ( 最短路 && 最短路建图 )
题意 : 给出二维平面上的两个点代表起点以及终点,接下来给出若干条地铁线路,除了在地铁线路上行进的速度为 40km/h 其余的点到点间都只能用过步行且其速度为 10km/h ,现问你从起点到终点的最短 ...
随机推荐
- 转:用ANT执行SQL
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=21340438&id=5160076 http://kayo.itey ...
- Ubuntu下修改DNS重启也能用的方法
1.通过修改:/etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)实现 内容填上需要修改的nameserver
- 删除 win8.1中的网络1,网络2,宽带连接1,宽带连接2等网络记录
新建txt文本,保存如下内容为reg文档: Windows Registry Editor Version 5.00 [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\W ...
- javascript语句语义大全(5)
1. var str = "abcd";alert(str.length);alert(str.charAt(0));//获取下标为0的字符alert(str.charCodeAt ...
- sql 日结
--生成日结数据 ==================================== -- Author: <Author,,Name> -- Create date: <Cr ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- js zhi网马
大家对木马都不陌生了,它可能要算是计算机病毒史上最厉害的了,相信会使木马的人千千万万,但是 有很多人苦于怎么把木马发给对方,现在随着计算机的普及,在网络上我相信很少有人会再轻易的接收 对方的文件了 ...
- PHP中require()文件包含的正确用法
以前看一些PHP框架源码的时候,很奇怪在文件包含的时候,会用dirname(__FILE__)来拼凑文件路 径,不知道这样做有什么好处,后来终于发现了其中的缘由. 我们来看一个简单的例子: 有a,b, ...
- Django: 之Model、Cookis、Session
到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用MySQLdb来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层执行数据库操作 im ...
- redmine配置邮件
作为一个项目管理平台,必须能够通知项目成员有关项目和任务的各种状态变化.这也是一种典型的观察者模式.开发人员可以跟踪某个任务,当任务状态.备注.文档.优先级等变化时开发人员就可以得到通知. 对于新配置 ...