摘要:
题目:http://poj.org/problem?id=1611求包括0号的集合的集合元素个数。方法一:用一个num数组计算第i个集合中的元素的个数View Code #include<stdio.h>#define maxn 30001int num[maxn],father[maxn];int flag;int find(int x){ int r=x; if(father[r]!=r) r=find(father[r]); int j,i=x; while(r!=i) { j=father[i]; father[i]=r; i=j; } return r;}void mer 阅读全文
posted @ 2011-07-22 15:20
渲染独白
阅读(157)
评论(0)
推荐(0)
摘要:
题目:http://poj.org/problem?id=2492方法一:用mark数组标记如果mark[x]%2==mark[y]%2那么xy就是同性的View Code #include<stdio.h>int father[2002],mark[2002];int find(int x){ int i=x; int j=father[x]; if(x!=father[x]) father[x]=find(father[x]); mark[x]=(mark[x]+mark[j])%2;////////////x与祖先的关系是由x与父节点的关系和父节点和祖先的关系决定的 whil 阅读全文
posted @ 2011-07-22 15:09
渲染独白
阅读(177)
评论(0)
推荐(0)


浙公网安备 33010602011771号