(简单) 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 ,现问你从起点到终点的最短 ...
随机推荐
- ORA-12170: TNS:Connect timeout occurred
VM 作为ORACLE 服务器,客户端登陆提示超时,本地连接使用网络连接正常. D:>sqlplus system/oracle123@//192.168.63.121:15021/pdb01 ...
- ZendStudio格式化HTML代码方法及格式化后错位问题修正
ZendStudio中格式化HTML快捷键:Ctrl+Shift+F 为什么html文件里面的内容格式化完都乱套了? 选 择window菜单->Preferences->Web->H ...
- Tinyxml封装类COperatorXml
OperatorXml.h头文件 #ifndef _OPERATOR_XML_H_ #define _OPERATOR_XML_H_ #include <string> class TiX ...
- myeclipse 2013 SR2 安装svn
1.下载SVN-site-1.8.22.zip 2.找到MyEclipse安装路径 我的是F:\tool\myeclipse2013\dropins,复制SVN-site-1.8.22.zip到此文件 ...
- Swift 响应式编程 浅析
这里我讲一下响应式编程(Reactive Programming)是如何将异步编程推到一个全新高度的. 异步编程真的很难 大多数有关响应式编程的演讲和文章都是在展示Reactive框架如何好如何惊人, ...
- nagios总结二
log_file=/usr/local/nagios/var/nagios.log # 定义nagios日志文件的路径cfg_file=/usr/local/nagi ...
- 基于Sublime Text搭建Python IDE
http://loosky.net/2967.html(包括SublimeREPL插件的安装和设置快捷键) SublimeCodeIntel,智能提示功能,查找自定义函数引用的快捷键--Alt+鼠标左 ...
- margin叠加相邻两个元素的上下margin是叠加在一起
<!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...
- 利用transform制作幻灯片
html代码 <html><head></head><body><div class='hpic'> <ul style=" ...
- PVST+(每个VLAN 的生成树PVST 加)
PVST+(每个VLAN 的生成树PVST 加) 实验拓扑: 分别在 SW1 和SW2 上show spanning-tree 查看结果: SW1#show spanning-tree VLAN000 ...