数据结构 并查集
文章平均质量分 85
Fsss_7
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
51nod1307 绳子与重物
链接:http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=61547 题意:中文题。。。 分析:直接二分就可以了,dfs判断。。但是!出题人说有O(n)的算法,我不甘心。下次补充。 PS:并查集做法:从叶子向根统计子树和,如果当前子树和大于根的负重,就从最后一个添加的点开始删除。详见代码。 代码: #include #include #include #include #include #include #include #inc原创 2016-01-19 22:42:01 · 1032 阅读 · 0 评论 -
poj3723Conscription
链接:http://poj.org/problem?id=3723 题意:n个女生m个男生,r对男女之间的关系d,招募一个人要花费10000,但是如果军营中已经有认识的人那么只需要10000-d。 分析:最大生成树。 代码: #include #include #include #include #include #include #include #include #include #i原创 2016-08-21 18:18:57 · 366 阅读 · 0 评论 -
hdu3461Code Lock
链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3461 题意:有一个长n的字符串锁,求这个锁有多少种不同的解锁方式,这个锁有若干个区间能够转动,两个能通过转动互相到达的情况属于同一种解锁方式。比如长度为1,如果没有区间就有'a'~'z'26中解锁方式。如果有一个转动区间[1,1],那么'a'->'b'->...'z',所以就只要1种解锁方式原创 2016-08-21 15:14:41 · 635 阅读 · 0 评论 -
hdu1598find the most comfortable road
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1598 题意:中文题。 分析:题目说点n=200实测好像有1000,因此RE了几次。原本的复杂度就有点大了,但是数据水。。思路就是先用并查集判能否达到终点,如果能到在去暴力枚举路径上的最小权值,然后只允许走大于最小权值的边,类似求最短一样求最小上界。O(q*m*nlogn) 代码: #include原创 2016-08-01 16:31:04 · 396 阅读 · 0 评论 -
hdu3938Portal
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3938 题意:给定一个n个点m条边的图,q个询问,每次询问给一个x,求有多少点对u,v使得u->v至少有一条路径满足路径中最大值小于等于x。 分析:其实就是求点对,离线一下,将边和询问都从小到大排序,然后用并查集合并就行了。 代码: #include #include #include #inclu原创 2016-08-03 21:50:02 · 467 阅读 · 0 评论 -
hdu3926Hand in Hand
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3926 题意:有n个人,m条关系,每条关系a,b说明a和b有一只手牵在一起,给定两组这样的关系,问是否同构。 分析:因为每个人只有2个手,只能形成环或链,那我们并查集合并集合,处理好环和链即可。 代码: #include #include #include #include #include #in原创 2016-08-03 20:38:18 · 397 阅读 · 0 评论 -
hdu1811Rank of Tetris
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1811 题意:中文题。 分析:先用并查集缩下点,然后用拓扑排序判断一些各种情况即可。 代码: #include #include #include #include #include #include #include #include #include #include #include #inc原创 2016-08-03 17:52:44 · 588 阅读 · 0 评论 -
BestCoder Round #77
链接:http://bestcoder.hdu.edu.cn/ 分析:1001,子集异或和的异或和,除了n==1的情况外所有元素都会在偶数个子集中出现,所以特判一下即可。O(n) 代码: #include #include #include #include #include #include #include #include #include #include #include #inc原创 2016-03-27 15:53:15 · 521 阅读 · 0 评论 -
poj2985The k-th Largest Group
链接:http://poj.org/problem?id=2985 题意:初始给定n个元素个数为1的集合,然后给定m个操作,有两种操作:C=0时输入a,b表示将a,b所在的集合合并成一个集合,C=1时输入k表示询问当前所有集合中集合大小排序中的第k大的集合的size。 分析:集合合并直接用并查集维护就可以了,找第k大的话用树状数组找第k大就好了。 代码: #include #include原创 2016-03-26 14:54:25 · 426 阅读 · 0 评论 -
Codeforces Round #346 (Div. 2)
链接:http://codeforces.com/contest/659 problemA:给定一个圆的周长n,初始在位置a,然后走b步,求最后位置在哪? 分析:不想分析。O(1) 代码: #include #include #include #include #include #include #include #include #include #include #include #i原创 2016-04-04 02:56:55 · 419 阅读 · 0 评论 -
Codeforces Round #345 (Div. 2)
链接:http://www.codeforces.com/contest/651 problemA:给定两个操作手柄的初始电量a,b,只有一个充电器,每一分钟如果不充电要消耗2%,在这分钟开始时就要消耗1%结束时再消耗1%,如果连上充电器会增加1%的电量。求两个手柄最多能撑多少分钟使得两个都有电。O(n) 分析:while下去就行了。。特判一下(1,1)的情况。 代码: #include原创 2016-03-09 19:49:28 · 489 阅读 · 0 评论 -
ICPCCamp2016day3 E.Intersection
链接:等camp过后挂出来再加 题意:给一组n,m表示有一个长为n的未知的字符串S,并且有m组关系,每组关系给定x,y,l表示在串S中的以第x个字符开始长度为l的子串和以第y个字符开始长度为l的子串相等。n,m 分析:首先暴力肯定是不可取的O(m*l),那么对于这种匹配式的统计该怎么办呢?首先要知道的时候加速匹配是肯定要的,怎么加速呢?我们将每一次的关系的l分成两部分2^k长度,就像rmq的询原创 2016-01-27 22:38:36 · 882 阅读 · 0 评论 -
Codeforces Round #379 (Div. 2) E. Anton and Tree
链接:http://codeforces.com/contest/734/problem/E 题意:给定一棵树,每个节点为黑色或白色,有一种操作:现在一个节点然后将与其联通的同颜色的节点一起变一种颜色(黑变白,白变黑),求最少多少次操作可以使得整棵树变成一个颜色。 分析:因为可以一个同颜色的联通块一起变,我们将所有同颜色的联通块缩点,然后我们会发现树变成了全是黑白交替的。那么最小操作次数就是从原创 2016-11-16 21:20:26 · 596 阅读 · 0 评论
分享