UVALive - 3644 并查集
来源:互联网 发布:苹果淘宝旗舰店是官方 编辑:程序博客网 时间:2024/05/01 18:42
并查集详细分析:http://blog.sina.com.cn/s/blog_87cb8e680100skd7.html
/* 主要是两个函数find 和 join. 本题大意,一些物品装车,来一件物品就要判断, 是否与已经装车的物品时联通的,联通不要,不连通装车,并且并到里面*/#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;int inf = 100010,pre[100010],num;int find(int x){ return pre[x] != x? pre[x] = find(pre[x]):x;}int join(int x,int y){ x = find(x), y = find(y); if(x == y) num++; else pre[x] = y;}int main(){ int x,y,i; while(cin>>x) { num = 0; for(i = 0; i < inf; i++) pre[i] = i; while(x != -1) { cin>>y; join(x,y); cin>>x; } cout<<num<<endl; }return 0;}
0 0
- UVALive - 3644 并查集
- uvalive 3644(并查集)
- UVALive 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive 6187 并查集
- uvalive 3027(并查集)
- UVALive - 3644X-Plosives(并查集)
- UVALive - 3644 - X-Plosives (并查集!!)
- UVALive(LA) 3644 X-Plosives (并查集)
- uvalive 3644 X-Plosives(并查集)
- UVALive 3644 X-Plosives(简单并查集)
- UVALive 3644 X-Plosives (并查集)
- X-Plosives +uvalive+并查集+水题
- Corporative Network +uvalive+并查集
- UVALive 6091 - Trees (并查集)
- 【UVALive】6168 Fat Ninjas 并查集
- UVALive 6091 Trees 并查集(水
- Ubuntu下安装配置samba
- PHP构造单例模式浅谈
- C3P0 in deadlocked PoolThrea
- 【机器学习算法-python实现】决策树-Decision tree(2) 决策树的实现
- C++ STL容器类vector使用范例
- UVALive - 3644 并查集
- JS生成GUID
- 用户态和内核态的概念区别
- 如何快速开发一个智能聊天机器人
- java的锁机制
- opecv配置记录
- Linux上的free命令详解
- linux中让程序后台执行
- Main函数参数argc,argv说明