![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并查集
Cifer
这个作者很懒,什么都没留下…
展开
-
POJ 1611 The Suspects
The SuspectsTime Limit: 1000MS Memory Limit: 20000KTotal Submissions: 13789 Accepted: 6543DescriptionSevere acute respiratory syndrome (SARS), an atypical pneumonia原创 2012-03-10 10:41:40 · 447 阅读 · 0 评论 -
HDOJ 1856 More is better
~~~题目链接~~~code:#include #define N 10000002int min = 0, max = 0, r[N], f[N];void init(){ for(int i = 0; i<N; i++) { r[i] = 1; f[i] = i; }}int find(int x){原创 2012-10-09 20:46:49 · 390 阅读 · 0 评论 -
HDOJ 1879 继续畅通工程
~~~题目链接~~~code:#include #include using namespace std;class node{ public: int x, y, c, flag; bool operator< (const node &s) const { return c<s.c;原创 2012-10-09 20:43:22 · 366 阅读 · 0 评论 -
HDOJ 1233 还是畅通工程
~~~题目链接~~~code:#include #include #include using namespace std;class node{ public: int x, y, c; bool operator< (const node &s) const { return c<s.c;原创 2012-10-09 20:42:10 · 386 阅读 · 0 评论 -
HDOJ 1232 畅通工程
~~~题目链接~~~code:#include #define N 1002int n = 0, m = 0, r[N], f[N];void init(int n){ for(int i = 0; i<=n; i++) { r[i] = 0; f[i] = i; }}int find(int x){ i原创 2012-10-09 20:41:09 · 325 阅读 · 0 评论 -
HDOJ 1875 畅通工程再续
~~~题目链接~~~code:#include #include #include using namespace std;struct node1{ int x, y;}num[102];struct node2{ int s, t; double c; bool operator <(const node2 &s) const原创 2012-10-09 20:45:21 · 412 阅读 · 0 评论 -
Vijos P1033 家族
~~~题目链接~~~水果~#include #define N 5002using namespace std;int n = 0, m = 0, p = 0, father[N], rank[N];int find(int x){ if(father[x] != x) father[x] = find(father[x])原创 2012-09-28 22:16:55 · 536 阅读 · 0 评论 -
POJ 2377 Bad Cowtractors (prime+堆优化)
题目链接:(—_—) zZ题目大意:有n个点, m条边,每条边有一定的花费, n个点是连通的(没有循环)且花费最大思路:用最小生成树算法就ok了, priem时要判重边code:prime+堆优化(第一回用,wa了半天)#include #include struct{ int weight, num;}dis[1002];int n原创 2012-07-19 15:10:49 · 780 阅读 · 0 评论 -
POJ 1988 Cube Stacking
题目链接:~( ̄▽ ̄~)(~ ̄▽ ̄)~code:#include int father[30001], num[30001], under[30001];//father存放根节点,num存放当前这个堆有多少个方块,under[i]存放第i个方块下有几个int find(int x){ int item = father[x];//记录上回合并时x所指向的根节点 if原创 2012-04-03 14:29:15 · 360 阅读 · 0 评论 -
POJ 1182 食物链
题目链接:~( ̄▽ ̄~)(~ ̄▽ ̄)~思路:用并查集,用rank[x]表示该节点与父节点的关系,rank[x] = 0表示同类 , rank[x] = 1表示吃 ,rank[x] = 2表示被吃在网上看了半天的向量法,图都没有个,看都看不懂,还是画图就懂了(没图没真相ㄟ(▔,▔)ㄏ )原创 2012-04-04 10:27:40 · 438 阅读 · 0 评论 -
HDOJ 1272 小希的迷宫 (并查集)
题目链接:(=^ ^=)思路:判断2点是不是在一个集合(是的话不行, 不是可以), 如果不在一个集合最后还要判断所有的点是不是在一个集合。(以下用一个集合中的点数与出现的点数判断)(wa了半天结果是数组开小了 纠结)code:#include #include int rank[100002], father[100002], used[100002], flag原创 2012-04-27 11:18:29 · 427 阅读 · 0 评论 -
HDOJ 1213 How Many Tables
Problem DescriptionToday 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 frien原创 2012-03-10 11:04:41 · 621 阅读 · 0 评论 -
HDOJ 1272 小希的迷宫
~~~题目链接~~~code:#include #define N 100002int flag = 0, max = 0, num[N], rank[N], father[N];void init(){ for(int i = 0; i<N; i++) { num[i] = 0; rank[i] = 0; f原创 2012-10-09 20:39:36 · 343 阅读 · 0 评论