CF218C:Ice Skating(并查集)
来源:互联网 发布:js引用 编辑:程序博客网 时间:2024/05/01 19:08
思路:将行相同或列相同的点合并为一棵树,最后看有多少棵树即可计算还需多少个点。
# include <stdio.h>int pre[101];struct node{ int x, y;}a[101];void init(int n){ for(int i=0; i<=n; ++i) pre[i] = i;}int find(int x){ if(x != pre[x]) pre[x] = find(pre[x]); return pre[x];}int main(){ int n; while(~scanf("%d",&n)) { init(n); int ans = 0; for(int i=0; i<n; ++i) scanf("%d%d",&a[i].x, &a[i].y); for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j) { if(a[i].x==a[j].x || a[i].y == a[j].y) { int px = find(i); int py = find(j); if(px != py) { ++ans; pre[py] = px; } } } printf("%d\n",n-1-ans); } return 0;}
0 0
- CF218C:Ice Skating(并查集)
- CF 并查集(或者图) Ice Skating
- CodeForces 217A Ice Skating(并查集思路)
- CodeForces 217 A.Ice Skating(并查集)
- Codeforces 217A. Ice Skating 【并查集】
- 并查集Codeforces Round #134 (Div. 1), problem: (A) Ice Skating
- Codeforces---Ice Skating
- A. Ice Skating
- CF 217A A. Ice Skating(贪心)
- codeforces 217A Ice Skating
- Codeforces 217A: Ice Skating
- [DFS] cf 134A Ice Skating
- Codeforces 217A. Ice Skating 搜索
- Codeforces 217A Ice Skating 题解
- 并查集(集并查)
- Codeforces Round #134 (Div. 2)C. Ice Skating
- Codeforces Round #134 (Div. 2) C. Ice Skating
- 并查集(含关系并查集)
- kswapd_shrink_zone
- 跟我学OpenResty(Nginx+Lua)开发目录贴
- leecode 解题总结:72. Edit Distance
- Madifest文件详解
- SmileHelp
- CF218C:Ice Skating(并查集)
- JavaScript深入浅出————函数和作用域(函数,this)(六)
- balance_pgdat
- IO流_字符缓冲输入流BufferedReader的使用
- 我的第一篇文章在CSDN下诞生了~
- 欢迎使用CSDN-markdown编辑器
- IO流_字符缓冲流复制文本文件案例1
- MVP+Dagger2+Rxjava+Retrofit+GreenDao 开发的小应用,包含新闻、图片、视频3个大模块,代码封装良好
- HDU-5178