
并查集
wwwiskey
学生
展开
-
POJ 1182 食物链
并查集的应用。 题意略。 题解:用数组a来表示x节点与父节点的关系,Union操作和Find操作看代码。 a[x] = 0 父子同类 a[x] = 1 子吃父 a[x] = 2 父吃子 #include #include using namespace std; const int MAXN = 50005; int set[MAXN], a[M原创 2013-01-29 17:45:44 · 863 阅读 · 0 评论 -
POJ 1988 Cube Stacking
并查集应用。 题意:初始有N个stack,编号为1-N,给两个操作 M x y :将x所在stack的所有cube移到y所在stack的上面 C x :统计在x下面的cube的个数 题解:fa[x]表示x的父节点,num[x]表示以x为根的并查集中节点的总数,rank[x]表示x在当前stack(并查集)中的排名 那么,在x下面的cube个数为: num[father(原创 2013-01-28 16:35:41 · 750 阅读 · 0 评论 -
POJ 1703 Find them, Catch them
并查集应用。 这个题目和【食物链】类似。 a[x] = 0 表示x与父节点同gang a[x] = 1 表示与父节点不同gang #include #include using namespace std; const int MAXN = 100005; int set[MAXN], a[MAXN]; int Find_set(int x) {原创 2013-01-29 21:02:24 · 2552 阅读 · 7 评论 -
POJ 2912 Rochambeau
并查集应用。 这道题目和 POJ 1182 食物链 非常类似。 枚举所有judge,不处理出现当前judge的round,然后利用食物链的解法判断冲突。就可以找出来最终的judge。 还有一步就是找到judge之后,要得到确定此judge的round数:这个round数就是在枚举的时候,其他人出错的round数的最大值——因为,到这个最大round数时,其他人都被排除,剩下的就是真正的jud原创 2013-02-01 18:04:07 · 985 阅读 · 0 评论