uva 1160 - X-Plosives
2013-10-24 10:50
267 查看
并查集的简单应用:
代码:
View Code
代码:
#include<cstdio> #define maxn 100005 using namespace std; int f[maxn]; int find(int x){return x==f[x]?x:f[x]=find(f[x]);} int main() { int x,y; while(scanf("%d",&x)!=EOF) { for(int i=0;i<maxn;i++)f[i]=i; int cnt=0; while(x!=-1) { scanf("%d",&y); x=find(x),y=find(y); if(x==y)cnt++; else f[x]=y; scanf("%d",&x); } printf("%d\n",cnt); } return 0; }
View Code
相关文章推荐
- acrobat-网格-参考线-网格大小设置
- Debian下Eclipse安装pydev cdt
- java ocject如何转换为int
- linux查找命令find
- 【HOW】如何允许编辑用户配置文件属性
- IIS配置文件的XML格式不正确 applicationHost.config崩溃 恢复解决办法
- 嵌入式c笔试题
- 【PAT Advanced Level】1010. Radix (25)
- 如何成为一名优秀的web前端工程师
- JS与JQUERY获取页面大小、滚动条位置、元素位置
- 上机项目--星号图2
- 窗口之间的脚本编程
- 支持向量机
- Myeclispe安装插件步骤(适用多款插件)
- iOS KVC KVO KVB
- linux软件安装命令
- memcached 安装使用
- 在set容器中存储结构体
- 如何快速改善 Domino 邮件系统的效率
- c++选择排序法