
数据结构之并查集
Conchpeng
贵在坚持。如有错误欢迎指正。
展开
-
The Suspects POJ - 1611
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 s原创 2017-05-20 20:21:09 · 275 阅读 · 0 评论 -
kuangbin并查集分析
1.Wireless Network题意:输入N(电脑数量),d(电脑修复后可联系的范围); 输入N台电脑的坐标,输入0&id代表修复编号为id的电脑,输入S X Y代表询问X,Y是否能 直接联系/间接联系思路:对于可联系的所有ID,均放到一个集合,想到并查集的作用,把具有相同性质(一定关联性)的东西放在一棵树上,并可以进行查询。2.The Suspects题意:输入n(学原创 2017-11-14 09:37:12 · 462 阅读 · 0 评论 -
D - How Many Answers Are Wrong HDU - 3038 【关系并查集】
题意:m个区间,及其和。问有几个错误。思路:sigma[l~r]=sigma[r]-sigma[l-1]。如果l-1和r有相同的最left值,说明它们的差值在之前已经准确的算出来了,只要判断是否和给的sum相同即可。否则之前没准确算出来,就可以把它们合并。合并注意回溯代码顺序问题,一定要返回par[x]#include #include using namespace std原创 2017-10-31 16:52:41 · 268 阅读 · 0 评论 -
树上战争 HDU-2545 【并查集】
题意:两个人A,B在树上的两个节点上,当一个人在一个节点的时候,节点的子树全都属于该者。 谁先占领了另一方的节点,那么该方胜利。思路: 并查集。 谁离根节点近,谁就是胜利者#include <bits/stdc++.h>using namespace std;typedef long long ll;int n,m;int par[100000+50];void init(){原创 2017-08-05 15:20:35 · 375 阅读 · 0 评论 -
How Many Tables HDU - 1213
Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, a原创 2017-05-20 18:18:57 · 270 阅读 · 0 评论 -
2017.5.24并查集小结
1.出现编号从1~n很可能用并查集(写了题发现的规律)2.写并查集有些题的时候可以开多几倍的数组实现(技巧)3.做题的时候一定要心静下来,不要看了这题想看那题,然后一题都做不好原创 2017-05-24 16:04:29 · 405 阅读 · 0 评论 -
Find them, Catch them POJ - 1703
The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which g原创 2017-05-24 15:57:40 · 273 阅读 · 0 评论 -
A Bug's Life POJ - 2492
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gen原创 2017-05-24 15:54:22 · 387 阅读 · 0 评论 -
食物链 POJ - 1182 卡了我好多天的题
动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说法是"2 X Y",表示X吃Y。 此人对N个动物,用上述两种说法,一句接一句地说原创 2017-05-23 17:02:48 · 385 阅读 · 0 评论 -
Codeforces Round #250 (Div. 2) D. The Child and Zoo
D. The Child and Zootime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOf course our child likes walking in a原创 2018-01-27 14:39:51 · 340 阅读 · 0 评论