POJ 1703 Find them, Catch them
来源:互联网 发布:传奇物品信息数据丢失 编辑:程序博客网 时间:2024/05/18 03:33
题目链接:http://poj.org/problem?id=1703
详细题解:种类并查集, 做完了食物链这道题果然是妥妥的 O(∩_∩)O~~~
详细做法请理解食物链那道题0.0……
#include<cstdio>#include<cstring>#define N 110000#define MOD 2int F[N];int rel[N];int fun(int x){ if(F[x] != x) { int fa_x = fun(F[x]); rel[x] = (rel[x] + rel[F[x]]) % MOD; F[x] = fa_x; } return F[x];}int main (){ int T; scanf("%d", &T); while(T--) { int n, m; scanf("%d %d", &n, &m); for(int i = 0; i <= n; i++) F[i] = i, rel[i] = 0; while(m--) { getchar(); char ch; int a, b; scanf("%c %d %d", &ch, &a, &b); int fa = fun(a); int fb = fun(b); if(ch == 'A') { if(fa != fb) printf("Not sure yet.\n"); else { int tmp = (2-rel[a]+rel[b])%MOD; if(tmp == 0) printf("In the same gang.\n"); else printf("In different gangs.\n"); } } if(ch == 'D') { if(fa != fb) { F[fb] = fa; rel[fb] = (2-rel[b]+1+rel[a]) % MOD; } } } } return 0;}
0 0
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ-1703 Find them, Catch them
- Poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703 - Find them, Catch them
- POJ 1703 Find them, Catch them
- POJ 1703(Find them, Catch them)
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703: Find them, Catch them
- poj 1703 find them,catch them
- POJ--1703--Find them, Catch them
- POJ 1703 Find them, Catch them
- 视其为编译警告而非编译错误
- 关于二叉树后续遍历算法的一点思考
- js事件的监听器的使用
- JS基础知识(基本类型 引用类型)
- Spark Streaming的WindowedDStream
- POJ 1703 Find them, Catch them
- 2013年4月通信概论答案
- 免安装版Tomcat注册Windows服务
- Linux下.bz2与.gz文件的区别
- C中的存储类、链接和内存管理
- java中栈与队列的实现
- BMFont中文字体图集制作的方法~(for unity ngui)
- Unity3D UI层 两个摄像头会出现两层UI的情况
- Coder-Strike 2014 - Qualification Round A. Password Check