poj1703 Find them, Catch them】的更多相关文章

poj(1703) Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26992   Accepted: 8188 Description 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, G…
https://vjudge.net/problem/POJ-1703 9ms多,卡着时间过了.上次一道并查集也是这样,总觉得要学一波并查集的优化.. 续:好像是可以只做一层存放敌人即可. #include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #include<cmath> #include<stack&…
题目链接 http://poj.org/problem?id=1703 题意 有两个帮派:龙帮和蛇帮,两个帮派共有n个人(编号1~n),输入m组数据,每组数据为D [a][b]或A [a][b],D[a][b]表示a,b属于不同的帮派,A [a][b]则让我们判断a,b是否属于一个帮派,根据判断的结果进行相应的输出. 思路 这题和poj2492很像,使用并查集解决,方法我已在poj2492的题解中写出,这里不再赘述. 代码 #include <cstdio> using namespace s…
Find them, Catch them   Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32225   Accepted: 9947 Description 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 Drag…
并查集. 这题错了不少次才过的. 分析见代码. http://poj.org/problem?id=1703 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; const char str1[] = "Not sure yet."; const char str2[] = "In different gangs."; c…
题意:食物链的弱化版本 解题关键:种类并查集,注意向量的合成. $rank$为1代表与父亲对立,$rank$为0代表与父亲同类. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cmath> using namespace std; typedef long long ll; #de…
做过一些的带权并查集,再来做所谓的"种类并查集",发现好像就顿悟了. 种类并查集与带权并查集实质上的区别并不大. 关键的区别就是种类并查集仅仅是带权并查集再弄个%取余操作而已.然后余数就表示他属于哪个种类. 这题仅仅有两个种类,也就是仅仅有0和1两种, 对于两个不同的种类,那么之间的权值是相差1的,所以依照带权并查集的方法做加上1.然后取余2就可以. #include<cstdio> const int N = 100005; int n, m, f[N], rank[N]…
题目地址:http://poj.org/problem?id=1703 题目大意:警察抓了n个坏蛋,这些坏蛋分别属于龙帮或蛇帮.输入m个语句,A x y询问x和y的关系(在一个帮派,不在,不能确定),D x y表示x和y不在一个帮派. 思路:种类并查集.维护一个数组rel[x]表示x和根节点的关系(0表示在一个帮派,1表示不在),初始全为0(自己和自己在一个帮派),更新rel用偏移量(rel[x]表示px->x,D x y表示x->y=1).由于2要特判,输入里分三类:1.n==2&&…
题目: 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 gang a criminal belongs to. The present questio…
题目链接:http://poj.org/problem?id=1703 这道题和食物链那道题有异曲同工之处,都是要处理不同集合之间的关系,而并查集的功能是维护相同集合之间的关系.这道题中有两个不同的集合,朴素并查集只能查询两者是否属于同一个集合,扩展并查集可以建立多个集合之间的关系. 本题我看了很多博客,对于两个集合,有许多博客都是采取2*n大小的并查集解决.大家的说法都是1-n属于一个集合,n-2*n属于另一个集合,我看的云里雾里,下面我想用我的方法来证明这样划分两个集合的正确性. 证明:我们…