hdu5486 离散化+并查集
来源:互联网 发布:重庆cnc编程最新招聘 编辑:程序博客网 时间:2024/05/06 19:57
#include<iostream>#include<stdio.h>#include<string.h>#include<string>#include<stdlib.h>#include<cmath>#include<queue>#include<algorithm>using namespace std;#define rd(x) scanf("%d",&x)#define rdd(x,y) scanf("%d%d",&x,&y)#define rddd(x,y,z) scanf("%d%d%d",&x,&y,&z)#define rdddd(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)#define rds(s) scanf("%s",s)#define rep(i,n) for(int i=0;i<n;i++)#define LL long longconst int N = 1e6+10;const int M=2000;const int inf=0x3f3f3f3f;const double eps=1e-8;int MOD=1e9+7;int cas=1;int n,m,k,q;int a[N];int b[N];int f[N*2];int c[N];int get(int x,int *a,int len){ return lower_bound(a+1,a+len+1,x)-a;}int find(int x){ if(f[x]==x) return x; return f[x]=find(f[x]);}int unit(int u,int v){ int u1=find(u),v1=find(v); if(u1!=v1){ f[u1]=v1; }}int res[N][2];int main(){#ifndef ONLINE_JUDGE freopen("aaa","r",stdin);#endif int T; rd(T); while(T--){ rd(n); for(int i=1;i<=n;i++) rdd(a[i],b[i]); for(int i=1;i<=n;i++) c[i]=a[i]; sort(c+1,c+n+1); int lena=1; for(int i=2;i<=n;i++) if(c[i]!=c[i-1]) c[++lena]=c[i]; for(int i=1;i<=n;i++) a[i]=get(a[i],c,lena); for(int i=1;i<=n;i++) c[i]=b[i]; sort(c+1,c+n+1); int lenb=1; for(int i=2;i<=n;i++) if(c[i]!=c[i-1]) c[++lenb]=c[i]; for(int i=1;i<=n;i++) b[i]=get(b[i],c,lenb); memset(res,0,sizeof res); for(int i=1;i<=lena+lenb;i++) f[i]=i; for(int i=1;i<=n;i++) unit(a[i],b[i]+lena); for(int i=1;i<=lena;i++){ int u=find(i); res[u][0]++; } for(int i=1;i<=lenb;i++){ int u=find(i+lena); res[u][1]++; } int one,mer,sp; one=mer=sp=0; for(int i=1;i<=lena+lenb;i++) { int u=res[i][0]; int v=res[i][1]; if(u==1 && v==1) one++; else if(u>1 && v==1) mer++; else if(u==1 && v>1) sp++; } printf("Case #%d: %d %d %d\n",cas++,sp,mer,one); } return 0;}
0 0
- hdu5486 离散化+并查集
- HDU 1856 并查集+离散化
- 【离散化\并查集\搜索】cake
- poj1733 并查集+离散化
- 校赛 (离散化 + 并查集)
- hdu 1856 离散化+并查集
- 【离散化+并查集】POJ_1733_Parity game
- POJ Parity game 离散化+并查集
- POJ1733离散化(未很好解决)+并查集
- 【枚举优化/离散化/并查集】染色问题
- poj 1733 - Parity game(离散化+并查集)
- poj 1733离散化(map)+并查集
- poj 1733(带权并查集+离散化)
- poj 1733 Parity game 并查集 离散化
- poj1733 Parity game(并查集+离散化--经典)
- pku1733 Parity game(离散化+并查集)
- poj 1733 Parity game 【种类并查集+离散化】
- Poj 1733 Parity Game(离散化+并查集)
- 黑马程序员-----c学习中的小程序
- 测试基础知识
- 软件复杂性分析
- google zxing编译
- 用python实现git blob对象的创建和查询
- hdu5486 离散化+并查集
- volley基本应用
- 黑盒测试基础知识
- C++学习记录之map容器和multimap容器
- poj 2152 树形dp(建立消防站)
- centos7将网卡名字改成eth样式
- 安装scikits.audiolab
- 一个简单的登陆界面
- ThinkPHP--模板与框架整合