
并查集
文章平均质量分 75
CCloth
这个作者很懒,什么都没留下…
展开
-
[并查集]Number of Groups Codeforces1691E
现在考虑两种不同的颜色,同样是将所有线段2n个点进行排序,然后扫描这些点,遇到右端点就将对应线段删除,遇到左端点就将对应线段加入集合,同时看一下集合中不同颜色的线段,让当前这条线段和不同颜色的所有线段进行连边,不过只保留右端点最长的那条线段,其余线段全部移除,因为多余的线段都被移除了,所以复杂度还是O(n)的,不会进行太多次连边。给出若干个红色或蓝色的线段,每条线段都有一个左端点和右端点,若两线段存在交集且颜色不用,则这两线段属于同一集合,问最终有多少个不同集合。原创 2023-01-11 11:49:40 · 597 阅读 · 0 评论 -
[并查集]修改数组 2019年蓝桥杯
题目描述给定一个长度为 N 的数组 A = [A1, A2, · · · AN ],数组中有可能有重复出现 的整数。现在小明要按以下方法将其修改为没有重复整数的数组。小明会依次修改 A2,A3,··· ,AN。当修改 Ai 时,小明会检查 Ai 是否在 A1 ∼ Ai−1 中出现过。如果出现过,则 小明会给 Ai 加上 1 ;如果新的 Ai 仍在之前出现过,小明会持续给 Ai 加 1 ,直 到 Ai 没有在 A1 ∼ Ai−1 中出现过。当 AN 也经过上述修改之后,显然 A 数组中就没有重原创 2022-01-20 21:11:03 · 248 阅读 · 0 评论 -
[并查集][思维]2021ccpc网络赛重赛Jumping Monkey
Problem DescriptionThere is a tree withnnodes andn−1edges that make all nodes connected. Each nodeihas adistinctweightai. A monkey is jumping on the tree. In one jump, the monkey can jump from nodeuto nodevif and only ifavis the greatest o...原创 2021-10-13 16:20:01 · 204 阅读 · 0 评论 -
[究极好题][带权并查集]How Many Answers Are Wrong HDU3038
TT and FF are ... friends. Uh... very very good friends -________-bFF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT should write down a sequence of integers-_-!!(bored).Then,原创 2021-10-09 22:30:44 · 252 阅读 · 2 评论 -
[并查集]The Suspects POJ1611
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others.In the Not-Spreading-Y原创 2021-10-09 20:13:23 · 135 阅读 · 0 评论 -
并查集删点总结
并查集删点操作需要借助虚点,实际上也就是一个映射罢了。通过index[i]表示i点经过映射后的编号,规定访问一个节点时只能通过它的编号index[i]来访问,初始时将各点的index[i]置为i,表示还未进行删点操作时都映射到本身,在删除点i时,将点i映射到一个虚节点上,即index[i] = m(m为虚节点编号),同时father[index[i]] = index[i] (表示删除点i后i点独立),之后所有涉及到点i的操作都用index[i]来代替,即m。这样的好处在于find()函数不需要修改原创 2021-10-09 19:30:43 · 613 阅读 · 2 评论 -
[并查集]Wireless Network POJ2236
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one b原创 2021-10-08 22:27:33 · 129 阅读 · 0 评论