Find them, Catch them POJ - 1703】的更多相关文章

题目链接: K - Find them, Catch them POJ - 1703 题目大意:警方决定捣毁两大犯罪团伙:龙帮和蛇帮,显然一个帮派至少有一人.该城有N个罪犯,编号从1至N(N<=100000.将有M(M<=100000)次操作.D a b 表示a.b是不同帮派A a b 询问a.b关系. 具体思路:带权并查集模板题.一般并查集都是相同的放在一个联通块里面.对于这个题,我们可以利用一下这个性质,只要是有联系的,都放进一个连通块里面,然后我们查询的时候,如果说他们的祖先一样的话,就…
链接: http://poj.org/problem?id=1703 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36768   Accepted: 11294 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 cit…
Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38668   Accepted: 11905 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 Drago…
抓住他们! 题目大意:两个黑社会帮派,互相打架,现在你很多条信息,要你确定两个人是否属于不同帮派 这题很有趣,题目不是直接给你两个人是否是一个帮派的,他给你的是不同帮派的,也就是给你很多个不同的要你找相同的. 乍看很麻烦,但是还记得我以前发布过一个食物链的题解吗! 食物链要求维护三个不同关系的集合,我第二种方法用的是偏移集!只用两个集合就搞定问题了. 这一题比食物链更简单,他只用维护两个就可以了. #include <iostream> #include <functional>…
题意:N个人,M次操作,操作一:A X Y,X,Y不是同一帮派,操作二:D X Y,判断X和Y的关系. 思路:如果X和Y不是同一帮派,那X与Y+N.Y与X+N是同一帮派,如果X与Y不在同一帮派且X与Y+N不是同一帮派则不能确定关系,如果X与Y是同一帮派则输出same那句话,如果X与Y+N是同一帮派则输出different那句话. 代码: #include<iostream> #include<cstdio> #include<cstring> #include<a…
Find them, Catch them Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1703 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs…
Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41463   Accepted: 12753 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 Drago…
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y均能C通信,则x和y可以通信.现在给出若干个操作, O p 代表修复编号为p的电脑 S p q代表询问p和q是不是能通信. 思路: 并查集即可.. 如果修复了一台电脑,则把与它相连距离不超过d的且修复了的放在一个集合里面. #include<cstdio> #include<cstring&…
不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network [传送门] POJ 1703 Find them, Catch them [传送门] 先上模板: #define MAXN 根据编号需要 int per[MAXN],rank[MAXN]; void init(int n) { int i; ;i<=n;i++) { per[i]=i;rank[i…
唉 不想说什么了 poj 1703,从看完题到写完第一个版本的代码,只有15分钟 然后一直从晚上八点WA到第二天早上 最后终于发现了BUG,题目要求的“Not sure yet.”,我打成了“No sure yet.” 然后是RQNOJ的NOIP真题,经典的能量项链 从看完题到写完伪码用了30分钟,敲完全部代码用了10分钟 WA 了7次,次次只能过前三个点,后面全部超时. 不能够啊?我动态规划了都,怎么可能超时? 开始优化主函数. 发现通过一个比较,能把N * (N-1)的复杂度降到C(N,2)…
Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43132   Accepted: 13257 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 Drago…
http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭虫(编号1-n)和m对关系,判断是否是出现同性恋的情况. 这题跟食物链的题类似,这里只有两种关系,关系是同性或者异性. 对于每只动物创建两个元素  同性或异性,并用这 2×n个元素建立并查集. 首先判断输入的x和y是否是一个组的.是就flag=1. 然后,如果x和y是一对,那么合并x和y+n,x+n…
题目:http://poj.org/problem?id=1703 题意:一个地方有两个帮派, 每个罪犯只属于其中一个帮派,D 后输入的是两个人属于不同的帮派, A后询问 两个人是否属于 同一个帮派. 用op[]数组记录 不跟自己在一个帮派中的一个人, 然后再输入不跟自己在一个帮派的人的时候,把 这个人跟 op[]数组记录里的那个人联系起来, 这两个人属于一个帮派. #include <iostream> #include <cstdio> #include <cstring…
Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31102   Accepted: 9583 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 Dragon…
Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 52925   Accepted: 16209 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 Drago…
题目地址:http://poj.org/problem?id=1703 Sample Input 1 5 5 A 1 2 D 1 2 A 1 2 D 2 4 A 1 4 Sample Output Not sure yet. In different gangs. In the same gang. 题目解读:T组数据,每组输入n m,n代表有n个人, m代表有m次操作.操作A x y:表示询问x y的关系是怎样的? 三中情况:不确定,属于同一个集合, 不属于同一个集合操作D x y:表示x y…
Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36176   Accepted: 11090 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 Drago…
手动博客搬家:本文发表于20170805 21:25:49, 原地址https://blog.csdn.net/suncongbo/article/details/76735893 URL: http://poj.org/problem?id=1703 题目大意:本题即很经典的"龙帮虎帮"问题. 有n个元素(n<=1e5),分布在两个不同的集合里. 现在有M个语句(m<=1e5),每个语句共两种:(1) 给定某两个元素在不同的集合中.(2) 询问两个元素是否在同一集合中.对…
[题目链接] http://poj.org/problem?id=1703 [算法] 并查集 + 拆点 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #i…
传送门 Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42463   Accepted: 13065 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 D…
题目:Find them,Catch them 刚开始以为是最基本的并查集,无限超时. 这个特殊之处,就是可能有多个集合. 比如输入D 1 2  D 3 4 D 5 6...这就至少有3个集合了.并且任意2个集合之间成员的敌我关系不明. 这里每个集合里面的成员关系要记录,他们在一个集合里,只是因为他们关系明确,敌人或者朋友. 千万不要简单的认为成朋友在一个集合,敌人在另外一个集合,分成2个集合.因为题目说只有2个匪帮,很容易进入这个误区. 我们只要记录一个成员和自己父亲的敌我关系和建树就可以了.…
Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30702   Accepted: 9447 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 Dragon…
Find them, Catch them 直接翻译了 Descriptions 警方决定捣毁两大犯罪团伙:龙帮和蛇帮,显然一个帮派至少有一人.该城有N个罪犯,编号从1至N(N<=100000.将有M(M<=100000)次操作.D a b 表示a.b是不同帮派A a b 询问a.b关系 Input 多组数据.第一行是数据总数 T (1 <= T <= 20)每组数据第一行是N.M,接下来M行是操作 Output 对于每一个A操作,回答"In the same gang.…
http://blog.csdn.net/freezhanacmore/article/details/8774033?reload  这篇讲解非常好,我也是受这篇文章的启发才做出来的. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 1…
题目大意: 在这个城市里有两个黑帮团伙,现在给出N个人,问任意两个人他们是否在同一个团伙输入D x y代表x于y不在一个团伙里输入A x y要输出x与y是否在同一团伙或者不确定他们在同一个团伙里 思路:并查集 #include<cstdio> #include<iostream> #include<cstring> #define M 100010 using namespace std; ]; int find(int x) { if(fa[x]==x)return…
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 Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present…
题意:有N名来自两个帮派的坏蛋,已知一些坏蛋两两不属于同一帮派,求判断给定两个坏蛋是否属于同一帮派. 思路: 解法一: 编号划分 定义并查集为:并查集里的元素i-x表示i属于帮派x,同一个并查集的元素同时成立 可见所有元素个数为2 * N,如果i表示属于帮派A,那么i + N表示属于帮派B,每次输入两个人不在同一帮派的时候,就合并他们分属两个帮派的元素. #include <iostream> using namespace std; #define MAX_N 100000 * 2 + 16…
<题目链接> 题目大意: 已知所有元素要么属于第一个集合,要么属于第二个集合,给出两种操作.第一种是D a b,表示a,b两个元素不在一个集合里面.第二种操作是A a b,表示询问a,b两个元素是否在同一个集合里面.如果不能确定的话打印not sure.否则给出答案. 解题分析: 典型的带权并查集,通过点与根节点的关系来判断它们是否属于同一阵营,而点与根节点的关系又是在状态压缩时,通过它与父亲节点的关系来更新. #include <cstdio> #include <cstr…
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 Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present…
  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 question…