食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 71361   Accepted: 21131 Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种. 有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同…
题目链接 每次给出两个昆虫的关系(异性关系),然后发现这些条件中是否有悖论 就比如说第一组数据 1 2 2 3 1 3 1和2是异性,2和3是异性,然后说1和3是异性就显然不对了. 我们同样可以思考一下这道题如何用带权并查集去做. 首先用r[x]存储的是x与其根节点rx的关系,0代表同性1代表异性(其实反着也一样因为这个关系是一个环状的) 这道题与上一道题唯一的不同是权值不是累加的关系而是相当于二进制的个位,也就是累加结果取%2. 这样就很容易仿照上一道题写出一下代码 #include<iost…
题目链接:http://poj.org/problem?id=1733 思路:这题一看就想到要用并查集做了,不过一看数据这么大,感觉有点棘手,其实,我们仔细一想可以发现,我们需要记录的是出现过的节点到根节点的1个奇偶性,这与区间端点的大小并没有关系,于是想到我们可以用map映射即可,这样就解决了大数据了.此外,如果0表示出现偶数个1,1表示出现奇数个1,然后就是向量偏移关系了(http://www.cnblogs.com/wally/archive/2013/06/10/3130527.html…
直接解释输入了: 第一行cases. 然后是n和m代表有n个人,m个操作 给你两个空的集合 每个操作后面跟着俩数 D操作是说这俩数不在一个集合里. A操作问这俩数什么关系 不能确定:输出Not sure yet. 在一个集合里:输出In the same gang. 不在一个集合里:输出In different gangs. 这题挺像http://poj.org/problem?id=2492同性恋的虫子那道题的. // by SiriusRen #include <cstdio> #incl…
#include<iostream> #include<cmath> #include<algorithm> using namespace std; ; // 东西 南北 int p[N],D[N],B[N]; struct node{ int x,y,d; ]; }e[N]; void init() { ; i < N ; i ++) { p[i] =i; D[i] =; B[i] =; e[i].x=,e[i].y=,e[i].d=; } } int fin…
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; <<; struct node { int l,r,ans; } q[N]; int a[N],fa[N],d[N],n,m,t_n; int get(int x) { if (x==fa[x]) return x; int root=get(fa[x]); d[x]^=d[fa[x]];//异或 retu…
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 gender. In his experiment, indi…
A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8528    Accepted Submission(s): 2745 Problem Description Background  Professor Hopper is researching the sexual behavior of a rare…
就是给一个无向图判是否有奇环 用带权并查集来做,边权1表示连接的两个节点异性,否则同性,在%2意义下进行加法运算即可,最后判相同的时候也要%2,因为可能有负数 #include<iostream> #include<cstdio> using namespace std; const int N=1000005; int T,n,m,f[N],s[N]; int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<…
题意: 思路: mod2 意义下的带权并查集 如果两只虫子是异性恋,它们的距离应该是1. 如果两只虫子相恋且距离为零,则它们是同性恋. (出题人好猥琐啊) 注意: 不能输入一半就break出来.....一定要读入所有的数据!!!! 因为是多组询问...被这个东西坑惨了. //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int cas…