HDU 2120 Ice_cream's world I(并查集)
来源:互联网 发布:淘宝如何申请部分退款 编辑:程序博客网 时间:2024/05/02 06:42
题目地址:HDU 2120
这题虽然字数不多,但就是看不懂。。意思是求最多有多少个被墙围起来的区域。显然就是求环的个数。然后用并查集求环个数就可以了。
代码如下:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int bin[2000];int find1(int x){ return bin[x]==x?x:bin[x]=find1(bin[x]);}int main(){ int n, m, ans, a, b, f1, f2, i; while(scanf("%d%d",&n,&m)!=EOF) { ans=0; for(i=0;i<n;i++) bin[i]=i; while(m--) { scanf("%d%d",&a,&b); f1=find1(bin[a]); f2=find1(bin[b]); if(f1==f2) ans++; else bin[f2]=f1; } printf("%d\n",ans); } return 0;}
0 0
- HDU 2120 Ice_cream's world I(并查集)
- hdu 2120 Ice_cream's world I 并查集
- HDU 2120 Ice_cream's world I 并查集
- HDU-2120-Ice_cream's world I【并查集】
- Hud 2120 Ice_cream's world I[并查集]
- HDOJ 2120 Ice_cream's world I(并查集)
- HD 2120 Ice_cream's world I 【并查集】
- HDOJ 2120 Ice_cream's world I (并查集)
- HDOJ 2120 Ice_cream's world I(并查集)
- Ice_cream's world I hdu 2120 并查集判断环
- hdu 2120 Ice_cream's world I(判断是否有环,简单的并查集)
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】
- hdu杭电2120 Ice_cream's world I【并查集】
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】
- hdu 2120 Ice_cream's world I (简单并查集 + 判环)
- HDU Problem 2120 Ice_cream's world I 【并查集检查环】
- 【HDU】-2120-Ice_cream's world I(并查集,环)
- HDU:2120 Ice_cream's world I(并查集+统计环的个数)
- ios如何调用facebook打开指定用户的主页
- Google Analytics(分析)数据收集限制和配额
- C#关于角色权限系统
- 正则表达式学习3
- CentOS 7.0 防火墙问题
- HDU 2120 Ice_cream's world I(并查集)
- 嵌入式 linux下kernel代码中记录生命周期的kref
- svn的merge使用例子
- 图像处理与计算机视觉:基础,经典以及最近发展(2)图像处理与计算机视觉相关的书籍
- jquery:提取亚马逊网站的dropdown下拉菜单
- 英语的沙漏——14年9月英语总结
- 编译和链接那点事<上>
- 我与C++设计模式(二)——单例模式
- Android xml资源文件中@、@android:type、@*、?、@+含义和区别