
HDU-2010 summer(1)最短路专题
xwc_hdu
HDU
展开
-
HDU 2544 最短路
<br />赤裸裸的最短路:Dijkstra算法<br />#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define INF 0x3fffffff int map[110][110]; int dis[110]; bool hash[110]; void init(int n) { for (int i = 1; i <= n; i++) {原创 2010-07-04 23:43:00 · 591 阅读 · 0 评论 -
HDU 2722 Here We Go(relians) Again
<br />就是题目长... 只要构好图就可以了。<br />1:each block is a square measuring 2520 rels per side 。<br />2:The speed limit between two adjacent intersections is always constant, and may range from 1 to 9 rels per blip<br />每条边的边长都是2520,速度1-9. 所以按time = 2520 / speed 构图原创 2010-07-07 09:23:00 · 876 阅读 · 1 评论 -
HDU 2962 Trucking 三种解法。
去年联合训练的一道题,题意大致是:最短路,求使卡车高度尽量高的情况下的最短路径。即求st->ed可通的情况下卡车高度的最大值,并求在该最大高度下的最短路径。(实际上就是路径上最小高度的最大值)比较传统的算法是二分高度+最短路。004453232010-07-02 15:31:47Accepted1011640 MS8280 KBVisual C++Slave_wc#include #include #include #include using namespace std; #define原创 2010-07-05 19:11:00 · 857 阅读 · 1 评论 -
HDU 1690 Bus System
题目比较简单,根据图给的方式建边(len->cost)。唯一需要注意的地方:each number is non-negative and not larger than 1,000,000,000.但是最多是100个点,路径最长的时候10^9 * (100 - 1)已经超出int范围了。004467282010-07-04 19:27:18Accepted1013171 MS304 KBVisual C++Slave_wc#include #include #include #include原创 2010-07-07 09:36:00 · 958 阅读 · 0 评论 -
HDU 2680 Choose the best route
<br />比较简单,加个超级源点就是最普通的最短路了。<br /> <br />004452552010-07-02 12:46:03Accepted1009250 MS4224 KBVisual C++Slave_wc<br /> <br />#include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std; #define INF 0x3fffffff #define原创 2010-07-05 10:25:00 · 680 阅读 · 1 评论 -
HDU 1874 畅通工程续
<br />赤裸的最短路, (diy 1003)2066一个人的旅行用邻接表写的不知为何没过,<br />拿来改一下,交diy(1004)这题是AC的。 。 。<br />#include <iostream> #include <cstring> #include <string> #include <cstdio> #include <map> #include <queue> #include <algorithm> using namespace std; #define MAXN原创 2010-07-05 07:43:00 · 552 阅读 · 0 评论 -
HDU 2066 一个人的旅行
<br />最短路, 求从k1个初始点 到 k2个终点中最短的一条路径长度。<br />设置一个超级源点 和 超级汇点即可, 使得超级源点到k1个初始点的权值为0,超级汇点. . .<br />下面是用priority_queue优化的Dijkstra代码:<br />78ms。<br />#include <iostream> #include <cstring> #include <cstdio> #include <queue> #include <algorithm> using name原创 2010-07-04 23:55:00 · 838 阅读 · 2 评论 -
HDU 2923 Einbahnstrasse
<br />题意: (N , C , and R)<br />图中总共有n个城市, c 辆坏掉的车停在c个城市, 修理厂在某城市x。<br />求c 辆车 从修理厂x出发将所有车拖回修理厂的总时间。(一辆车拖回厂后再重新出发去拖第二辆,不同时拖运。)<br /> <br />#include <iostream> #include <cstring> #include <cstdio> #include <queue> #include <string> #include <map> using原创 2010-07-05 10:33:00 · 888 阅读 · 2 评论 -
HDU 1217 Arbitrage
<br />题意:<br />某些币种之间可以通过一定比率进行兑换,<br />问是否存在一种币种 经过若干次currency exchang回到原币种时,能够得到盈利。<br />即求 st * v1 * v2 * ... * vn * st 的一个最大值。<br />(1<=n<=30) 数据量较小,用动态规划思想的Floyd能求的最大值。<br /> <br />004452342010-07-02 11:40:04Accepted100846 MS300 KBVisual C++<br />Sla原创 2010-07-05 10:17:00 · 867 阅读 · 0 评论 -
HDU 1548 A strange lift
<br />电梯每层上有两个按钮 up,down 对应一个数ki。<br />若按 up 则上升 ki 层, down则下降 ki 层。<br />求how many times at least he have to press the button "UP" or "DOWN"?。<br /> <br />只是统计按键的次数,按一次,count 增一, 因此是无权图,简单bfs即可。<br /> <br />004451012010-07-01 23:40:54Accepted100731 MS276原创 2010-07-05 09:58:00 · 568 阅读 · 1 评论 -
HDU 1142 A Walk Through the Forest
<br />题目大意是给你一个图。起点为1,终点为2<br /><br />然后点a到点b是合法的判断(Notice 1:)是当b存在一个到终点的距离小于a到终点的最小距离,求从起点到终点的路径数。<br /> <br />Notice 1:不合法并非是断路,合法指回家的时候只按dis[b] < dis[a]的路线走、<br />dis[]表示到终点2的最短路径, 满足dis[b] < dis[a], 表示这样a->b的是可选择的。 就是说每次回家时选择从距起点(最短距离)近的点 向 距起点(最短距离)远的原创 2010-07-05 08:24:00 · 891 阅读 · 0 评论 -
HDU 2112 HDU Today
最短路径,就是地名是字符串,以前写这题是用字典树来hash,那样写起来麻烦点下面是用map来hash地名的。//pass:用邻接表写不知为何就是过不掉, 改成邻接阵就过了。。。下回再看看004443152010-06-30 15:03:13Accepted10031265 MS392 KBGNU C++Slave_wc#include #include #include #include #include #include using namespace std; #define原创 2010-07-05 07:33:00 · 755 阅读 · 1 评论 -
HDU 1385 Minimum Transport Cost
题意:求最短路并输出字典序最小的路径。。。 基本思路是:对从 start ->j 最短路径长度相同的点 ,进行比较他们路径的字典序。 这题WA很多次, 主要是在比较字典序的时候应该要从 start->j 进行比较的。 而我理所当然的以为, 因为比较的最后一个节点是相同的, 就只从start -> pre[j] 进行比较, 这样就错了 . . . . . . 例: 1->2->5原创 2010-07-05 09:47:00 · 774 阅读 · 2 评论