POJ-1703-Find them, Catch them
来源:互联网 发布:windows系统排名 编辑:程序博客网 时间:2024/06/07 01:48
这个题是给你一些信息,D a b表示a和b是不同的,A a b是询问a、b是否是相同的
用并查集做,这个题同样需要用到偏移量的思想,给所有人分组分别标号为1和0,然后更新的时候注意更新偏移量即可
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int maxn=1e5+100;int n,m,p[maxn],diff[maxn];int find(int x){ if(p[x]==-1)return x; int y=p[x]; p[x]=find(p[x]); diff[x]=(diff[y]+diff[x])%2; return p[x];}int main(){ int T; scanf("%d",&T); while(T--) {scanf("%d%d",&n,&m);memset(p,-1,sizeof(p));memset(diff,0,sizeof(diff));while(m--){ char op[5]; int a,b; scanf("%s%d%d",op,&a,&b); if(op[0]=='A') {int x=find(a);int y=find(b);if(x!=y) printf("Not sure yet.\n");else if(x==y&&diff[a]==diff[b]) printf("In the same gang.\n");else printf("In different gangs.\n"); } else {int x=find(a);int y=find(b);if(x!=y){ p[x]=y; diff[x]=(diff[a]+diff[b]+1)%2;} }} } return 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
- NSString NSData 转换与常见的 NSString 和 NSMutableString 方法
- 认识服务器的几大必备知识
- crontab
- Jquery初识
- Object-c学习之路六(oc字符串文件读写)
- POJ-1703-Find them, Catch them
- Java Reflection: Generics
- CStrollView 滚动条
- java队列和栈的使用
- MySql控制台修改用户密码
- 网上找的一个“回到顶部”的小链接
- [Linux] rlwrap - 解决Linux下sqlplus退格、上翻键乱码问题
- iOS4 and wireless application deploy
- 将matlab中数据保存为txt或dat格式