HDU 1829 A Bug's Life(种类并查集)】的更多相关文章

思路:见代码吧. #include <stdio.h> #include <string.h> #include <set> #include <vector> #include <queue> using namespace std; ; int n,m; int father[maxn]; int num[maxn]; //num[i]表示 int rel[maxn]; //rel[i]表示它与根节点的关系,0代表同性,1代表异性 void…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829 并查集的一个应用,就是检测是否存在矛盾,就是两个不该相交的集合有了交集.本题就是这样,一种虫子有两种性别,每次m次操作,每次给出(a,b),如果a和b是同性别就出现了错误,也就是说出现了判断它有两种性别的错误.我的策略同样是两个集合,用并查集维护两个集合之间的关系.具体证明请看我的上一篇博客,关于这种做法的正确性的证明. 代码如下: #include<bits/stdc++.h> typed…
A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 28211   Accepted: 9177 Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders…
题目链接:http://poj.org/problem?id=2492 A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 39415   Accepted: 12835 Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes th…
传送门 关键在于到根节点的距离,如果两个点到根节点的距离相等,那么他们性别肯定就一样(因为前面如果没有特殊情况,两个点就是一男一女的).一旦遇到性别一样的,就说明找到了可疑的 #include<bits/stdc++.h> using namespace std; ],n,m,rankk[]; bool flag; inline void init() { flag=false; ; i<=n; ++i) f[i]=i, rankk[i]=; } int getf(int v) { if…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19429    Accepted Submission(s): 6206 Problem Description Background Professor H…
先说说种类并查集吧. 种类并查集是并查集的一种.但是,种类并查集中的数据是分若干类的.具体属于哪一类,有多少类,都要视具体情况而定.当然属于哪一类,要再开一个数组来储存.所以,种类并查集一般有两个数组,一个存并查集内的父子关系,一个存各个节点所属的种类关系. 以这道题为例(题意在后面,如果没有读题,可以先看完题在来看这部分)—— 这道题很明显,将bug分成两类,一公一母.但是实际上我们并不关心它是公的还是母的,只关心它们之间是同性还是异性.所以,我们可以设与并查集的根节点同性的为0,反之为1.所…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829 题意:就是给你m条关系a与b有性关系,问这些关系中是否有同性恋 这是一道简单的种类并查集,而且也比较简单只要比较给出的两个点是否有相同祖宗如果有那么他们距离祖宗结点的距离是否为偶数 如果是偶数那么他(她)们必然是同性恋. #include <iostream> #include <cstring> #include <cstdio> using namespace s…
http://acm.hdu.edu.cn/showproblem.php?pid=1829   A Bug's Life Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1829 Description Background Professor Hopper is researching the sexual behavior of a…
A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 45757   Accepted: 14757 题目链接:http://poj.org/problem?id=2492 Description: Background : Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes…