acm-并查集
文章平均质量分 56
u013700636
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
poj1703(基于分组)
一开始拿到这题不知道该怎么去做,想用opposite[i]来保存相对立的数,最后做出来连样例都跑不起来,查说有两种做法: 一:分组,把1~n看成一组,把n+1~2n看成相对立的另一组; 二:用并查集的便宜向量来做; 先给出用分组来做的; #include const int maxn=1e5+5; int p[maxn<<1]; int find(int x) { return原创 2014-03-12 19:27:59 · 760 阅读 · 0 评论 -
poj2524_并查集基础
和上一篇hdu1232基本一样,就cnt=-1改为cnt=0 #include int set[50005]; int find(int x) { int r=x; while(r!=set[r]){ r=set[r]; } int i=x; while(i!=r){ int j=i; i=set[i];原创 2014-03-12 01:09:09 · 677 阅读 · 0 评论 -
hdu1232-我的第一道并查集
很水的一道题,并查集入门,find有用路径压缩 #include int set[1005]; int find(int x) { int r=x; while(r!=set[r]){ r=set[r]; } int i=x; while(i!=r){ int j=i; i=set[i];原创 2014-03-12 00:47:07 · 618 阅读 · 0 评论 -
poj2492-并查集基于分组
和poj1703的题很相似,也是用分组来做;等学会了向量偏移量再补吧; #include const int maxn=2000+10; int p[maxn<<1]; int find(int x) { return p[x]==x?x:p[x]=find(p[x]); } int main() { int T,cas=0; scanf("%d",&T);原创 2014-03-12 20:10:51 · 732 阅读 · 0 评论 -
poj2236-数据赶脚弱爆了
这题好像不考虑一点连接多点也可以过,= =!上参考代码 #include #include #include #include #include using namespace std; #define N 1110 int d; bool use[N]; struc原创 2014-03-14 23:26:55 · 850 阅读 · 0 评论 -
hdu1829基于分组
这是一个bug群,在poj上它们叫2492,在hdu它们叫1829。呵~ 尝试用偏移向量来做,结果连样例都不过,无奈只好又回到老本行分组来做。等偏移向量用熟了再重做吧 #include const int N=2005; int p[2*N]; int find(int x) { return x==p[x]?x:p[x]=find(p[x]); } int main() {原创 2014-03-15 18:18:48 · 648 阅读 · 0 评论 -
poj1182-用物理来理解偏移向量,So easy!
一开始看解题报告,完全云里雾里中,之后自己突然灵光一现,用物理的思想把她给理解了,so easy! (提示在看这篇文章之前请看我的《并查集的偏移向量的学习》的转载文章,我不想重复造轮子,还望谅解!) 所谓的偏移量,个人赶脚类似于物理中的参考点,由物体与参考点之间的距离推断出物体与物体之间的位移,引用到这里其实就相当于根是参考点,由结点与根的关系,推出结点与结点的关系(这样想一想高中学的物理也不原创 2014-03-15 16:58:36 · 1052 阅读 · 0 评论
分享