LA 3644 X-Plosives
最简单的并查集
多做做水题,加深一下理解
//#define LOCAL
#include <cstdio> const int maxn = + ;
int parent[maxn]; int GetParent(int a) { return parent[a] == a ? a : parent[a] = GetParent(parent[a]); } int main(void)
{
#ifdef LOCAL
freopen("3644in.txt", "r", stdin);
#endif int x, y;
while(scanf("%d", &x) == )
{
for(int i = ; i < maxn; ++i) parent[i] = i;
int cnt = ;
while(~x)
{
scanf("%d", &y);
x = GetParent(x); y = GetParent(y);
if(x == y) ++cnt;
else parent[x] = y;
scanf("%d", &x);
}
printf("%d\n", cnt);
}
return ;
}
代码君
LA 3644 X-Plosives的更多相关文章
- LA 3644 - X-Plosives ( 也即UVA 1160)
LA看题 请点击:传送门 UVA 上也有这题 :UVA 1160 - X-Plosives 题目大意就是如果车上存在 k 个简单化合物,正好包含 k 种元素 ,那么它们将有危险,此时你应该拒绝装车. ...
- 并查集(图论) LA 3644 X-Plosives
题目传送门 题意:训练指南P191 分析:本题特殊,n个物品,n种元素则会爆炸,可以转移到图论里的n个点,连一条边表示u,v元素放在一起,如果不出现环,一定是n点,n-1条边,所以如果两个元素在同一个 ...
- LA 3644 易爆物 并查集
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- [LA] 3644 - X-Plosives [并查集]
A secret service developed a new kind of explosive that attain its volatile property only when a spe ...
- LA 3644 易爆物
https://vjudge.net/problem/UVALive-3644 简单的并查集题目. #include<iostream> using namespace std; + ; ...
- LA 3644 简单并查集
题目大意:有一些简单的化合物,每个化合物由两种元素组成,把这些化合物按顺序装车,若k个化合物正好包含k种元素,那么就会爆炸.避免爆炸,有些化合物就不能装车.求有多少个不能装车. 题目分析:若k个化合物 ...
- ACM数据结构相关资料整理【未完成,待补充】
在网上总是查不到很系统的练ACM需要学习的数据结构资料,于是参考看过的东西,自己整理了一份. 能力有限,欢迎大家指正补充. 分类主要参考<算法竞赛入门经典训练指南>(刘汝佳),山东大学数据 ...
- UVALive(LA) 3644 X-Plosives (并查集)
题意: 有一些简单化合物,每个化合物都由两种元素组成的,你是一个装箱工人.从实验员那里按照顺序把一些简单化合物装到车上,但这里存在安全隐患:如果车上存在K个简单化合物,正好包含K种元素,那么他们就会组 ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
随机推荐
- MYSQL注入天书之order by后的injection
Background-9 order by后的injection 此处应介绍order by后的注入以及limit注入,我们结合less-46更容易讲解,(在less46中详细讲解)所以此处可根据l ...
- java基础知识回顾之抽象类和接口的区别
/* 抽象类和接口的异同点: 相同点: 都是不断向上抽取而来的. 不同点: 1,抽象类需要被继承,而且只能单继承. 接口需要被实现,而且可以多实现. 2,抽象类中可以定义抽象方法和非抽象方法,子类继承 ...
- Linux :Can't start up: not enough memory
http://stackoverflow.com/questions/9634577/linux-cant-start-up-not-enough-memory
- log4net 一分钟上手
1. 首先从apache网站下载log4net, http://logging.apache.org/log4net/download_log4net.cgi .我下的是最新版本 log4net- ...
- 针对局域网IM飞秋(feiq)的开发总结
先上代码了,通过java代码群发feiq消息: package com.triman.constant; import java.io.IOException; import java.io.Unsu ...
- 【hdu3341-Lost's revenge】DP压缩+AC自动机
题意:给定只含有A.G.C.T的n个模板串,一个文本串,文本串任意两个字母可互换位置,问最多能匹配多少个模板串.注意:匹配同一个模板串匹配了两次,ans+=2:(可重复) 题解: 原本想到一个简单dp ...
- mysql 死锁检查
今天看了一篇关于死锁检查的blog. Advanced InnoDB Deadlock Troubleshooting – What SHOW INNODB STATUS Doesn’t Tell Y ...
- lintcode:寻找旋转排序数组中的最小值 II
寻找旋转排序数组中的最小值 II 假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2). 你需要找到其中最小的元素. 数组中可能存在重复的元 ...
- C#格式化输出
double a = 12354.365; Console.WriteLine(string.Format("{0:f4}", a)); 输出a的四位小数
- web.xml配置bug之提示The content of element type "web-app" must match "(icon?,display- name?,description?,distributable?,
错误:配置web.xml时,出现红色叉叉,提示 The content of element type "web-app" must match "(icon?,disp ...