ACM之并查集
文章平均质量分 71
noname40
这个作者很懒,什么都没留下…
展开
-
poj 1182 食物链(并查集+向量偏移)
这道食物链实在让我纠结了好久。。。1182 食物链(并查集+向量偏移)" title="poj 1182 食物链(并查集+向量偏移)" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px;原创 2012-01-18 10:53:42 · 1193 阅读 · 0 评论 -
poj 1308 并查集判断“树”
题意:判断“带方向的树”,这道题,基本是参考了网上的代码。。。 思路:并查集 #include using namespace std; int pre[500]; bool vis[500]; void make_set()//初始化 { for(int i=0;i<499;i++) pre[i]=i,vis[i]=0; } int find_set(int x) { retur原创 2012-02-28 22:33:23 · 375 阅读 · 0 评论 -
poj 1703 并查集
题意:输入A的时候 判断后面两个数的关系,输入D的时候后面两个数代表不在一个团伙。。。这题,按着食物链那个题瞎弄的,神奇的AC了,太爽了。。。 思路:并查集,给出D的时候就合并,但同时要更新关系。relation 0 1 代表 在同一伙和不在同一伙 #include using namespace std; struct node { int parent; int relation原创 2012-02-29 10:34:52 · 290 阅读 · 0 评论 -
poj 2492 并查集 a bug's life
题意:给出一些不同种类的昆虫,然后判断给出的关系中是否有矛盾的关系。 思路:带关系类型的并查集,不同种类的昆虫进行合并,同时更新关系。 #include using namespace std; struct node { int parent; int relation; }p[2010]; int N; void make_set() { for(int i=1;i<=N;i+原创 2012-02-29 22:09:37 · 422 阅读 · 0 评论 -
poj 2236 并查集 计算机网络
题意:给出N,d代表有N个计算机,还有可以建立连接的限制距离d。O 后面的数字代表了维修好的计算机,S 后面的两个数字用来判断,这两个计算机是否建立的连接。 思路:并查集,每修好一个计算机,进行标记,同时枚举所有计算机,在维修好的计算机中,找出可以建立连接的计算机,进行合并。 #include #include using namespace std; struct point { int原创 2012-02-29 22:16:25 · 398 阅读 · 0 评论 -
poj 1988 并查集 搬箱子的问题
题意:输入N,代表了有N个箱子,没个箱子可以看作是一个“栈”,M后面的a b 操作是把a箱子所在的栈中的箱子,整体放到b箱子所在的栈的顶部,画画图就懂了。C后面的数字是判断这个箱子的下面还有几个箱子 思路:并查集。 #include using namespace std; struct node { int parent;//父亲节点 int count;//元素下的个数原创 2012-02-29 22:26:06 · 536 阅读 · 0 评论 -
hdu 1232 畅通工程
题意:不解释 思路:并查集最基本的应用,m个城市需要建造m-1条道路,如果不连通(根节点不相同)那么就合并,就少建一条道路。 #include using namespace std; int pre[1005]; int find(int x)//非递归的查集 { int r=x; while(pre[r]!=r) r=pre[r]; int j=x; while(j!=r)原创 2012-01-18 10:56:42 · 331 阅读 · 0 评论