随笔分类 -  数据结构—并查集

摘要:题目链接昨天晚上没有做出来,刚看题目的时候还把题意理解错了,当时想着以什么样的顺序倒,想着就饶进去了,也被题目下面的示例分析给误导了。题意:有1-n种化学药剂 总共有m对试剂能反应,按不同的次序将1-n种试剂滴入试管,如果正在滴入的试剂能与已经滴入的试剂反应,那么危险数*2,否则维持不变。问最后最大... 阅读全文
posted @ 2014-07-07 19:30 水门 阅读(305) 评论(0) 推荐(0)
摘要:题目InputLine 1: Two integers, N and M (1 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn = 200000+10; 7 int bin[maxn], dis... 阅读全文
posted @ 2014-05-21 16:55 水门 阅读(190) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2492题意:跟上一道1703题差不做,给出m对昆虫交配,问 有没有同性恋。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn = 2010; 8 int bin[maxn], op[maxn], n; 9 void init()10 {11 for(int i = 1; i <= n; i++)12 {13 bin[i] = i;14 op... 阅读全文
posted @ 2014-02-17 20:34 水门 阅读(179) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=1703题意:一个地方有两个帮派, 每个罪犯只属于其中一个帮派,D 后输入的是两个人属于不同的帮派,A后询问 两个人是否属于 同一个帮派。用op[]数组记录 不跟自己在一个帮派中的一个人, 然后再输入不跟自己在一个帮派的人的时候,把这个人跟 ... 阅读全文
posted @ 2014-02-17 19:58 水门 阅读(157) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2513参考博客:http://blog.csdn.net/lyy289065406/article/details/6647445http://www.cnblogs.com/LK1994/p/3263462.html 1 #include... 阅读全文
posted @ 2013-08-24 20:39 水门 阅读(195) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=16110号是病原,求多少人有可能感染 1 #include 2 #include 3 #define maxn 50000 4 5 int u,v,bin[maxn]; 6 int find(int x) 7 { 8 return bin[x]==x?x:(bin[x]=find(bin[x])); 9 };10 11 int main()12 {13 int n,m,i,j,x,y,k,sum,t;14 while(~scanf("%d%d",&n,&m)&&(n!=0||m!=0 阅读全文
posted @ 2013-08-19 19:45 水门 阅读(227) 评论(0) 推荐(0)
摘要:题目:http://poj.org/problem?id=2524题意:问一个大学里学生的宗教,通过问一个学生可以知道另一个学生是不是跟他信仰同样的宗教。问学校里最多可能有多少个宗教。也就是给定一个图的点数和相应的边,问有多少个连通分量。 1 #include 2 #include 3 #include 4 5 using namespace std; 6 int bin[50010]; 7 8 int find(int a) 9 {10 if(bin[a]!=a)11 return bin[a]=find(bin[a]);12 };13 14 int main()15 {... 阅读全文
posted @ 2013-06-27 22:58 水门 阅读(243) 评论(0) 推荐(0)
摘要:以前做过的一个题,今天又做了一次。 1 #include 2 #include 3 #define maxn 2000 4 5 int u[maxn],v[maxn],bin[maxn]; 6 int find(int x) 7 { 8 return bin[x]==x?x:(bin[x]=find(bin[x])); 9 };10 11 int main()12 {13 int n,m,i,sum,x,y;14 while(~scanf("%d",&n)&&n)15 {16 sum=n-1;17 scanf("%d",& 阅读全文
posted @ 2013-05-23 08:36 水门 阅读(174) 评论(0) 推荐(0)
摘要:View Code 1 #include "stdio.h" 2 int bin[1002]; 3 4 int findx(int x) 5 { 6 int r,j,i; 7 r = x; 8 while (bin[r] != r) 9 r = bin[r];10 i = x;11 while (i != r)12 {13 j = bin[i];14 bin[i] = r;15 i = j;16 }17 return r;18 }19 20 void merge(... 阅读全文
posted @ 2013-03-13 23:19 水门 阅读(157) 评论(0) 推荐(0)