POJ 2502 最短路】的更多相关文章

http://poj.org/problem?id=2502 同一条地铁线上的站点相邻点间按照v2建边,然后所有点之间按照v1更新建边,所有的边都是双向边,both directions. 然后直接跑dij就好了,防止因为重复的站点多建了同样的点,把上限开到了500,AC. 一个小bug是因为数组开了500,然后初始化时访问了500导致越界,,,把其他位置的地址更改了检查了半天,衰,以后还是多开几十好点. #include<iostream> #include<cstdio> #i…
题意:给出地铁线  起点和 终点  坐地铁速度为v2  走路为v1 求起点到终点的最短距离  (答案需要四舍五入这里坑了好久) 拿给出的地铁站点 和起点终点建边即可  然后跑个迪杰斯特拉 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; ; ; int n; +; double dist[maxn]; double cost[m…
做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 -> n - 1 d[i] = dis[0][i] while u = GetNearest(1 .. n - 1, !been[]) been[u] = 1 for_each edge from u d[edge.v] = min(d[edge.v], d[u] + dis[u][edge.v]…
POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离) 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.…
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你求从编号为1的城市到编号为n的城市的路线中,最大能经过多重的车. 解题思路 这个题可以使用最短路的思路,不过转移方程变了\(dis[j]=max(dis[j], min(dis[u], e[u][j]))\).这里dis[j]表示从标号为1的点到达编号为j的点的路径中,最小的承重能力,就像短板效应样…
Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L 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 s…
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…
题目链接: 题意:在一个城市里有许多地铁,现在你知道每条地铁的起点  终点与停站点的坐标,知道我们的起始坐标与终点坐标,问加上走路最快到达终点的时间是多少? 方法:求出任意两点的车速时间与步行时间,再算出最短路 #include<stdio.h> #include<cstring> #include<cstdlib> #include<algorithm> #include<math.h> #include<queue> using…
题意 : 给出二维平面上的两个点代表起点以及终点,接下来给出若干条地铁线路,除了在地铁线路上行进的速度为 40km/h 其余的点到点间都只能用过步行且其速度为 10km/h ,现问你从起点到终点的最短路是多少? 分析 : 这题建完图之后就是裸的最短路了,在建图的时候需要注意地铁的站点之间不能隔点建拥有地铁行进速度的边,也就是若地铁线路为 A->B->C 那么则不能建 A->C 这条速度为 40km/h 的边,因为地铁是在节点间行进的,如果要跨站点那么只能通过步行.图中边的权值为 (两点间…
题意: 给出两个坐标,分别是小明家和小明学校的坐标. 给出多条地铁线,给出每站的坐标,已知地铁是双向的,每条线以-1 -1结尾. 给出地铁速度,步行速度. 地铁线可看成是顺次连接的线段. 求小明从家到学校用到的时间. 思路: 任何两点之间都可以连速度为步行的无向边,地铁相邻两站可以连速度为地铁速度的无向边. 之后进行SPFA: #include<stdio.h> #include<string.h> #include<math.h> #include<queue&…