
图论
文章平均质量分 78
JakeYoung
这个作者很懒,什么都没留下…
展开
-
HDU 2066 一个人的旅行 - from lanshui_Yang
Problem Description虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景……草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女……眼看寒假就快到了,这么一大段时原创 2013-07-13 09:47:13 · 1426 阅读 · 0 评论 -
POJ 1251 Jungle Roads(最小生成树水题) - from lanshui_Yang
最小生成树模板题,不再敖述。 代码如下:#include#include#include#include#include#include#include#include#include#define mem(a , b ) memset(a , b , sizeof(a))using namespace std ;const int MAXN = 10原创 2013-09-27 21:29:55 · 1224 阅读 · 0 评论 -
LA 5854 Long Distance Taxi (SPFA 变型) - from lanshui_Yang
题目大意:直接抽象一下,有多个城市,这些城市之间有n条无向边,有一个旅行家(假设叫Mike),他有一辆摩托车,摩托车的邮箱大小为cap,其耗油量是 10千米/每升油,给定一个起点、一个终点和cap的值以及有加油站的城市 (Mike 可以在这些城市加满油),让你判断Mike是否可以从起点到达终点,如果可以,就求出路程的最小值,否则,就输出"-1"。 解题思路:这道题是一道变型的最短路问原创 2013-09-27 20:36:41 · 1488 阅读 · 0 评论 -
POJ 1236 Network of Schools(强连通 + 想法)- from lanshui_Yang
DescriptionA number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes software (th原创 2013-09-22 12:11:23 · 1056 阅读 · 0 评论 -
POJ 1094 Sorting It All Out (拓扑排序) - from lanshui_Yang
DescriptionAn ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequenc原创 2013-09-18 15:50:49 · 1148 阅读 · 0 评论 -
POJ 1330 Nearest Common Ancestors(tarjan , 倍增法求LCA) - from lanshui_Yang
题目大意:给你一棵树,让你求结点 u 和 v 的最近公共祖先(即LCA)。 解题思路:这道题我学习了两种方法。一种是 tarjan 算法(dfs + 并查集) ,另一种是倍增法。tarjan算法是一种离线算法,较易理解,不再详述。着重谈一下在线算法 : 倍增法求LCA 。 tarjan 算法程序如下:#include#include#inclu原创 2013-09-16 20:37:47 · 5960 阅读 · 0 评论 -
POJ 2449 Remmarguts' Date (SPFA + A星算法) - from lanshui_Yang
题目大意:给你一个有向图,并给你三个数s、t 和 k ,让你求从点 s 到 点 t 的第 k 短的路径。如果第 k 短路不存在,则输出“-1” ,否则,输出第 k 短路的长度。 解题思路:这道题是一道简单的启发式搜索题目。而启发式搜索中A星算法是比较好理解的。A星算法中需要用到一个估价函数:f(n) = g(n)+ h(n)。其中,g(n)是当前量,h(n)是估计量,两者之和 f原创 2013-09-29 22:22:01 · 2075 阅读 · 1 评论 -
POJ 1273 Drainage Ditches(EK) - from lanshui_Yang
题目大意不再敖述,此题是一道基础的最大流。用EK直接水过。。。但要注意,输入中可能存在重边,要记得处理,还有,别忘了处理回流,HDU的题目数据较水(不处理回流也能过)。第一道网络流题目,纪念下。。。 请看代码:#include#include#include#include#include#include#includeusing namespace std ;原创 2013-08-29 10:27:12 · 835 阅读 · 0 评论 -
POJ 1679 The Unique MST - from lanshui_Yang
DescriptionGiven a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E). A spanning tree of G原创 2013-09-09 22:21:49 · 1079 阅读 · 0 评论 -
HDU 2255(KM) - from lanshui_Yang
这是一道比较典型的KM算法题 ,先写一下O( n ^ 4)的算法,程序如下:#include#include#include#include#include#include#define mem(a , b) memset(a , b , sizeof(a))using namespace std ;const int MAXN = 305 ;const int INF原创 2013-10-18 15:27:37 · 942 阅读 · 0 评论 -
POJ 2195 Going Home(KM)- from lanshui_Yang
题目大意:一张图中,有相等数量的“m” 和 “H” ,分别代表人和房子,要求通过移动人使最终每个房子里都有一个人,输出最小的移动步数。 解题思路:这题是求最小权值匹配,可用KM算法求解,需要注意的是,KM算法求的是最大权值匹配,这里需要把每条边的权值取反,得到最大权值匹配后,再把答案取反。 请看代码:#include #include #incl原创 2013-10-26 11:05:01 · 1001 阅读 · 0 评论 -
POJ 3169 Layout(差分约束) - from lanshui_Yang
题目大意:有 n 头牛 ,他们站成一条线,假设这条线是一条数轴,第 i 头牛所站的位置为 Si ,则首先必须满足如下条件: 1、对于所有的 i ( 2 = 0 然后又有ML 个条件: Sb - Sa 和MD个条件:原创 2013-11-11 19:59:13 · 1022 阅读 · 0 评论 -
POJ Chores - from lanshui_Yang
题目大意:给你 n 个任务,编号从 1 ~ n , 有些任务有前驱任务 ,即前驱任务完成后才能开始该任务,当然,相互之间没有影响的任务可以同时进行,完成每个任务都需要一定的时间,问:完成这些任务的最少时间是多少? 解题思路:这个题有点像拓扑排序,因为要开始每个任务前都要完成某些任务,即任务的完成是有先后顺序的,具体方法就是:将每个任务看成一个点,将入度为 0 的点压入队列,然后遍原创 2013-11-08 20:47:17 · 962 阅读 · 0 评论 -
POJ 1469 COURSES (二分匹配) - from lanshui_Yang
题目大意:有 p 个学生和 n 门课 , 每一个门课程可以被多个学生选,问:在每个学生只能选一门课的情况下,能否使 p 个学生每个人选的课程都不相同? 解题思路:这是一道简单的求最大匹配问题,只要求出此图的最大匹配,然后判断是否与 p 相等即可。 请看代码:#include #include #include #include #include原创 2013-11-07 19:47:11 · 910 阅读 · 0 评论 -
POJ 1274 The Perfect Stall(二分匹配)- from lanshui_Yang
题目大意不再敖述,就是赤裸裸的求最大匹配,只是顺手复习下匈牙利算法,呵呵。 代码如下:#include#include#include#include#include#include#include#include#define mem(a , b) memset(a , b , sizeof(a))using namespace std ;co原创 2013-11-05 21:33:34 · 761 阅读 · 0 评论 -
HDU 4435 charge-station - from lanshui_Yang
题目大意:这里有n个城市, 编号为1 ~ n , 你是一个旅行家,要从城市1 出发,经过所有城市,然后回到城市1 ,(注意:每个城市可以访问多次) , 你的交通工具是一辆摩托车, 油箱的容量为 d 升,并且每升油可以使摩托车行驶 1 公里,为了使到所有城市旅游成为可能, 要在一些城市建造加油站,并且在城市 i 建造加油站的费用为2 ^ (i - 1) , 请设计一个方案决定在哪些城市建加油站可以使原创 2013-11-05 19:30:51 · 1024 阅读 · 0 评论 -
POJ 1201 Intervals (差分约束) - from lanshui_Yang
题目大意:给你 n 个区间[ai , bi] (1 = ci ,找出包含元素个数最少的 集合 Z , 并输出其大小 。 解题思路:这是一道差分约束题,设 s[ i ] 表示集合Z中 小于等于 数字 i 的元素个数,则由题意得出如下约束条件: 1、对于所有的[ai , bi] , 有 s[ bi ] - s[ai - 1] >= ci ,变换后得s[ ai -原创 2013-10-28 22:09:20 · 954 阅读 · 0 评论 -
POJ 3013 Big Christmas Tree - from lanshui_Yang
题目大意:给你 n 个节点,编号从1 到 n ,节点 1 为根节点,并且每个节点都有一个重量 w ,现在要在这些点之间建设公路,要求必须包含所有节点并且使整个图连通,总费用为 每条边的单价 * (该边所有子节点的重量之和) 。其实这是一个最短路的问题,经过推倒,总费用 = 每个节点的重量 * 该节点到根节点(节点1)的最短路径。 Ps:此题卡精度 , 需用long long ,原创 2013-10-25 21:18:24 · 1032 阅读 · 0 评论 -
POJ 2400 Supervisor, Supervisee (KM + 回溯) - from lanshui_Yang
题目大意:有 n 个老板 和 n 个员工 ,每个老板对每个员工都有一个满意度(范围 1 ~ n ,1 代表最满意),每个员工对每个老板也有一个满意度(范围1 ~ n , 1 代表最满意),但每个老板只能雇佣一个员工 , 每个员工也只能为一个老板工作,定义 :平均满意度 = ((每个人的满意度之和) - 2 * n )/ (2 * n) ,要求找出是平均满意度最小的分配方案,如果有多种方案,则按员工原创 2013-10-26 17:09:51 · 947 阅读 · 0 评论 -
POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang
DescriptionKatu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean operator op (one of AND, OR, XOR) and an integer c (0 ≤ c ≤ 1). One Katu is solvable i原创 2013-09-09 09:17:55 · 1078 阅读 · 0 评论 -
POJ 2942 Knights of the Round Table - from lanshui_Yang
DescriptionBeing a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very原创 2013-09-02 17:04:39 · 925 阅读 · 0 评论 -
ZOJ 1654 Place the Robots(超牛的建图思路) - from lanshui_Yang
Place the RobotsTime Limit: 5 Seconds Memory Limit: 32768 KBRobert is a famous engineer. One day he was given a task by his boss. The background of the task was the following:Given a map原创 2013-08-03 09:54:15 · 1578 阅读 · 0 评论 -
POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang
Problem DescriptionAs we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of原创 2013-08-02 21:45:22 · 1235 阅读 · 0 评论 -
HDU 4619 Warm up 2 (2013 多校第二场) - from lanshui_Yang
Problem Description Some 1×2 dominoes are placed on a plane. Each dominoe is placed either horizontally or vertically. It's guaranteed the dominoes in the same direction are not overlapped, but hor原创 2013-08-02 14:16:49 · 1313 阅读 · 0 评论 -
HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang
感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直径最小。 解题思路:此题先求出原始树的直径maxr1,并记录直径上的各个节点。很容易想到要移动的边一定是直径上的边,只有这样才有可能使树的直径减小!! 接着就是枚举原创 2013-07-24 21:52:49 · 1392 阅读 · 1 评论 -
HDU 2196 Computer - from lanshui_Yang
Problem DescriptionA school bought the first computer some time ago(so this computer's id is 1). During the recent years the school bought N-1 new computers. Each new computer was connected to one o原创 2013-07-24 10:37:21 · 855 阅读 · 0 评论 -
POJ 2513 Colored Sticks - from lanshui_Yang
题目大意:给定一捆木棒,每根木棒的每个端点涂有某种颜色。问:是否能将这些棒子首位项链,排成一条直线,且相邻两根棍子的连接处的颜色一样。 解题思路:此题是一道典型的判断欧拉回路或欧拉通路的问题,以木棍的端点颜色为顶点。方法是:先用并查集判断图是否连通,然后统计奇度顶点的个数sumj , 如果 sumj == 0 , 则图中存在欧拉回路 ;如果 sumj == 2 , 则图中存在欧拉通路 ;原创 2013-07-30 14:33:05 · 884 阅读 · 0 评论 -
HDU1878 欧拉回路 - from lanshui_Yang
Problem Description欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路。现给定一个图,问是否存在欧拉回路?Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是节点数N ( 1 束。Output每个测试用例的输出占一行,若欧拉回路存在则输出1,否则输出0。原创 2013-07-19 14:26:53 · 1037 阅读 · 0 评论 -
POJ 1300 Door Man - from lanshui_Yang
DescriptionYou are a butler in a large mansion. This mansion has so many rooms that they are merely referred to by number (room 0, 1, 2, 3, etc...). Your master is a particularly absent-minded lou原创 2013-07-13 15:40:52 · 1090 阅读 · 0 评论 -
ZOJ 2588 Burning Bridges(求含重边的无向连通图的割边) - from lanshui_Yang
Burning BridgesTime Limit: 5 Seconds Memory Limit: 32768 KB Ferry Kingdom is a nice little country located on N islands that are connected by M bridges. All bridges are very beautiful and ar原创 2013-08-04 14:07:54 · 1307 阅读 · 0 评论 -
POJ 1523、ZOJ 1119 SPF - from lanshui_Yang
DescriptionConsider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in th原创 2013-08-03 21:56:58 · 1165 阅读 · 0 评论 -
LA 3211 Now or later (2 - SAT) - from lanshui_Yang
As you must have experienced, instead of landing immediately, an aircraft sometimes waits in a holding loop close to the runway. This holding mechanism is required by air traffic controllers to space原创 2013-09-07 17:03:01 · 1487 阅读 · 0 评论 -
1062 昂贵的聘礼 (spfa + 等级枚举) - from lanshui_Yang
题目是中文的,大意不在敖述。这道题抽象以后就是一个求最短路的问题,只不过,每个点访问的条件有限制,样例建立的有向图如下:原创 2013-08-30 10:56:13 · 1274 阅读 · 0 评论 -
POJ 1135 Domino Effect (spfa + 枚举)- from lanshui_Yang
DescriptionDid you know that you can use domino bones for other things besides playing Dominoes? Take a number of dominoes and build a row by standing them on end with only a small distance in bet原创 2013-08-29 15:13:47 · 1090 阅读 · 0 评论 -
POJ 2553 The Bottom of a Graph - from lanshui_Yang
DescriptionWe will use the following (standard) definitions from graph theory. Let V be a nonempty and finite set, its elements being called vertices (or nodes). Let E be a subset of the Cartesian原创 2013-08-17 11:31:57 · 1002 阅读 · 0 评论 -
POJ 2186 Popular Cows - from lanshui_Yang
DescriptionEvery cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <= 50,000) ordered pairs of the form (A, B) that t原创 2013-08-15 21:40:43 · 1006 阅读 · 0 评论 -
POJ 2762 Going from u to v or from v to u? (Tarjan) - from lanshui_Yang
DescriptionIn order to make their sons brave, Jiajia and Wind take them to a big cave. The cave has n rooms, and one-way corridors connecting some rooms. Each time, Wind choose two rooms x and y,原创 2013-08-14 17:23:18 · 954 阅读 · 0 评论 -
POJ 1904 King's Quest - from lanshui_Yang
DescriptionOnce upon a time there lived a king and he had N sons. And there were N beautiful girls in the kingdom and the king knew about each of his sons which of those girls he did like. The son原创 2013-08-19 10:56:39 · 1074 阅读 · 0 评论 -
POJ 3177 Redundant Paths - from lanshui_Yang
DescriptionIn order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotte原创 2013-08-05 22:41:18 · 1327 阅读 · 0 评论 -
POJ 3683 Priest John's Busiest Day (2 - SAT) - from lanshui_Yang
题目大意:一个城镇里只有一个牧师,在国庆节这一天,他要为 n 对夫妇的婚礼祷告,这 n 对夫妇婚礼的开始时间 s 、结束时间 e 和祷告时间 d 不尽相同,但是祷告只能在每个婚礼的开始或结束时进行(如一个婚礼的开始时间为s , 结束时间为 e , 那么祷告的时间就为 s ~ s + d 或 e - d ~ e)。问:这个牧师是否能为所有的婚礼祷告,如果能,则输出为每个婚礼祷告的开始时间和结束时间。原创 2013-11-14 21:16:24 · 1049 阅读 · 0 评论