并查集
chen_zan_yu_
同是寒窗苦读,岂能甘拜下风
展开
-
C - How Many Tables (裸并查集)
Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, a...原创 2018-11-03 10:40:36 · 133 阅读 · 0 评论 -
Cube Stacking POJ - 1988 (并查集)
Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes labeled 1 through N. They start with N stacks, each containing a single cube. Farmer John asks Betsy to perform ...原创 2019-04-06 23:11:23 · 165 阅读 · 0 评论 -
食物链 POJ - 1182 (有权---并查集)
动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法是"1 X Y",表示X和Y是同类。第二种说法是"2 X Y",表示X吃Y。此人对N个动物,用上述两种说法,一句接一句地说出K句话,...原创 2019-04-07 18:53:34 · 211 阅读 · 0 评论 -
(转)超有爱的并查集~~~
原作者(飘过小牛)看完后,我发现自己喜欢上周芷若师太啦~~~(当然,并查集也会了)首先在地图上给你若干个城镇,这些城镇都可以看作点,然后告诉你哪些对城镇之间是有道路直接相连的。最后要解决的是整幅图的连通性问题。比如随意给你两个点,让你判断它们是否连通,或者问你整幅图一共有几个连通分支,也就是被分成了几个互相独立的块。像畅通工程这题,问还需要修几条路,实质就是求有几个连通分支。如果是1个...转载 2019-04-03 15:20:30 · 180 阅读 · 0 评论 -
超超有爱爱-----并查集~~~
感谢---华东理工大学---罗勇军教授先看一下这篇(有周芷若童鞋哟),再看这篇效果更好哦并查集(Disjoint Set):一种非常精巧而实用的数据结构。 用于处理不相交集合的合并问题。 经典应用:连通子图 最小生成树Kruskal算法 最近公共祖先 应用背景:“帮派”一个城市中有n个人,他们属于不同的帮派; 已知这些人的关系,例如1号、2号是朋友,1...原创 2019-04-03 16:09:05 · 460 阅读 · 0 评论 -
Ubiquitous Religions POJ - 2524 (并查集)
There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university beli...原创 2019-04-03 17:01:46 · 92 阅读 · 0 评论 -
Dragon Balls HDU - 3635 (并查集)
有几天没做了,hhhh~~~Five hundred years later, the number of dragon balls will increase unexpectedly, so it's too difficult for Monkey King(WuKong) to gather all of the dragon balls together.His cou...原创 2019-04-13 00:17:49 · 300 阅读 · 0 评论 -
小希的迷宫 HDU - 1272 (并查集)
上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了回头路)。小希现在把她的设计图给你,让你帮忙判断她的...原创 2019-04-16 23:57:51 · 101 阅读 · 0 评论 -
Is It A Tree? HDU - 1325 (并查集)
A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties.The...原创 2019-04-18 00:03:45 · 203 阅读 · 0 评论 -
A Bug's Life POJ - 2492
BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gend...原创 2019-04-06 08:56:17 · 155 阅读 · 0 评论 -
Wireless Network POJ - 2236 (并查集)
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n...原创 2019-04-05 23:34:40 · 176 阅读 · 0 评论 -
Find them, Catch them POJ - 1703 (种类并查集(影子并查集))
The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which g...原创 2019-04-04 22:39:47 · 174 阅读 · 0 评论 -
B - The Suspects (并查集)
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to s...原创 2018-11-03 11:18:15 · 157 阅读 · 0 评论 -
D - How Many Answers Are Wrong
抵达时抵达---题目链接 TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin w...原创 2018-11-03 11:50:56 · 565 阅读 · 0 评论 -
A - Wireless Network (并查集)
滴答滴答---题目链接 An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all comp...原创 2018-11-03 00:18:48 · 100 阅读 · 0 评论 -
M - 小希的迷宫
滴答滴答---题目链接 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了回头路)。小希现在把她的...原创 2018-11-12 10:53:39 · 107 阅读 · 0 评论 -
Is It A Tree?
滴答滴答---题目链接 A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following prope...原创 2018-11-12 11:05:13 · 166 阅读 · 0 评论 -
The Suspects POJ - 1611 (并查集---经典之套模板)
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to s...原创 2019-04-03 20:52:01 · 165 阅读 · 2 评论 -
fjut 2144 并查集
滴答滴答---题目链接并查集详解:这里注意一下,用递归压缩路径的同学,可能会爆栈,从而导致Runtime Error 建议用循环压缩路径数据量比较大推荐使用scanfInput输入多组数据每组数据第一行是两个整数n(1<=n<=10^6),m(1<=m<=10^6)。分别表示元素数、操作数(初始时每个元素以自己为一个集合,元素编号是1-n)接...原创 2019-04-04 17:29:20 · 139 阅读 · 0 评论 -
POJ 1703 Find them, Catch them(种类并查集)
The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which g...原创 2019-04-04 17:35:39 · 149 阅读 · 0 评论 -
Farm Irrigation HDU - 1198 (并查集)
滴答滴答---题目链接思路:水管连通本质上就是集合的合并,最后求有几个集合的问题,很容易想到并查集 只需要对每个地块与右方和下方的地块进行合并即可,合并之前先判断是否能连通, 若能连通则合并,不能连通,则不能合并 每种水管用一个由'0'和'1'组成的长度为4的字符串代表, 分别表示上下左右四边是否有接口,'0'无,'1'有#include <iostream>...原创 2019-04-19 00:10:11 · 159 阅读 · 0 评论