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

1
摘要:地址:http://codeforces.com/contest/1465/problem/C 题意: 给出n*n的棋盘,初始m个棋子,初始位置:一行只有一个棋子,一列只有一个棋子。 移动:水平或垂直移到任意一个位置。 将所有棋子移到主对角线上,需要最少的步数。每次移动的落点必须要符合:一行只有一个 阅读全文
posted @ 2020-12-21 21:56 liyexin 阅读(438) 评论(0) 推荐(0)
摘要:地址:https://www.acwing.com/problem/content/839/ 只是记录个板子,不做解析。 #include<cstdio> #include<cstring> #include<vector> #include<algorithm> #include<iostream 阅读全文
posted @ 2020-11-02 21:16 liyexin 阅读(129) 评论(0) 推荐(0)
摘要:acwing评测地址:https://www.acwing.com/problem/content/description/2071/ 解析: 如果每次操作2,都要对修改点的所在树都修改一遍,显然是很慢的。 那么定义一个d[],d[i]表示i点与根节点之间的信息量差值,定义now[i],表示i点本身 阅读全文
posted @ 2020-10-15 09:10 liyexin 阅读(407) 评论(0) 推荐(1)
摘要:地址:https://ac.nowcoder.com/acm/contest/5673/I 题意: n次,每次给出a,b; 可以进行三种操作: 1.不选 2.a如果之前没选过,可选a 3.b如果之前没选过,可选b 求可以获得的最大数目 解析: 首先用map进行一个离散化处理 假设把每次输入的看成一条 阅读全文
posted @ 2020-08-04 18:18 liyexin 阅读(132) 评论(0) 推荐(0)
摘要:地址:http://poj.org/problem?id=3321 题意: 树上有n个位置,初始每个位置都有苹果。以1号为总根 n-1条分叉边 m条询问: Q:id 以id为根的子树有几个苹果 C:id id处如果有苹果,摘掉,否则放上一个苹果。 解析: 假设输入的是这么一棵树: 看数据,肯定要前缀 阅读全文
posted @ 2020-06-09 17:41 liyexin 阅读(212) 评论(0) 推荐(0)
摘要:地址:http://poj.org/problem?id=2985 题意: 输入n,m。共n只猫,m组询问。 1,L,R。L号猫所在组和R号猫所在组合并 0,x。查询第x大组有几只猫。 解析: 理解了好久的说。。。最最重要的还是树状数组的本质要理解好,要不代码写再多也没用。 树状数组:c[i]表示所 阅读全文
posted @ 2020-05-24 18:57 liyexin 阅读(207) 评论(0) 推荐(0)
摘要:地址:https://ac.nowcoder.com/acm/contest/5158/H 解析:1e9,开不了这么大的pr[],所以采取离散化处理。假设输入了 10 12 ,可以把它们存到另一个数组now[]里:i=1,10 i=2,12,这样就可以把数字用坐标来代替,n只有1e6,所以pr[]开 阅读全文
posted @ 2020-04-26 00:19 liyexin 阅读(219) 评论(0) 推荐(0)
摘要:Problem Description Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes 阅读全文
posted @ 2020-04-08 18:22 liyexin 阅读(194) 评论(0) 推荐(0)
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1325 Is It A Tree? Problem Description A tree is a well-known data structure that is either empty (null, 阅读全文
posted @ 2020-04-07 21:01 liyexin 阅读(272) 评论(0) 推荐(0)
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1272 Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该 阅读全文
posted @ 2020-04-06 23:23 liyexin 阅读(210) 评论(0) 推荐(0)
摘要:More is better Problem Description Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the 阅读全文
posted @ 2020-04-06 22:17 liyexin 阅读(126) 评论(0) 推荐(0)
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=3635 Dragon Balls Five hundred years later, the number of dragon balls will increase unexpectedly, so it' 阅读全文
posted @ 2020-04-06 22:02 liyexin 阅读(131) 评论(0) 推荐(0)
摘要:地址:http://poj.org/problem?id=1182 Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。 有人用两种说法对这 阅读全文
posted @ 2020-04-06 00:00 liyexin 阅读(174) 评论(0) 推荐(0)
摘要:地址:http://poj.org/problem?id=1988 Description Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes labeled 1 through N. T 阅读全文
posted @ 2020-04-03 16:47 liyexin 阅读(203) 评论(0) 推荐(0)
摘要:A Bug's Life Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different gend 阅读全文
posted @ 2020-03-30 23:46 liyexin 阅读(186) 评论(0) 推荐(0)
摘要:Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, 阅读全文
posted @ 2020-03-29 17:14 liyexin 阅读(152) 评论(0) 推荐(0)
摘要:题意:输入n,m。n个人,m个规定/询问。一共有两个集合,A:询问a,b是否在同一个集合?D:表明a,b不在同一个集合。输出有三种,不在同一集合,在同一集合,不确定。 解析:其实有点离散化的意思。传统并查集是合并两个集合,而这个题是分开两个集合。那么可以这么做,想办法进行合并操作。输入a,b,a,b 阅读全文
posted @ 2020-03-20 12:03 liyexin 阅读(179) 评论(0) 推荐(0)
摘要:地址:http://poj.org/problem?id=1611 题意:n,m。n个人,编号0-n-1,m个组合:第一个数表示本集合个数,后面是成员。一个成员可以在多个集合里。0号是病人,跟她一个组合的全是病人,问一共有多少人患病。 解析:直接并查集基本模板,加入一个vis[]数组来记录与本节点相 阅读全文
posted @ 2020-03-19 17:24 liyexin 阅读(148) 评论(0) 推荐(0)
摘要:迟来的笔记,早就学了并查集了,只是没有搬到博客园,一直存放在本地里了。 放两个讲得好的链接以便于复习:https://blog.csdn.net/dellaserss/article/details/7724401 https://www.xuebuyuan.com/3212977.html 找寻根 阅读全文
posted @ 2020-03-18 16:42 liyexin 阅读(752) 评论(0) 推荐(0)
摘要:A very big corporation is developing its corporative network. In the beginning each of the N enterprises of thecorporation, numerated from 1 to N, org 阅读全文
posted @ 2019-07-19 16:20 liyexin 阅读(304) 评论(0) 推荐(0)

1