HDOJ 2120 Ice_cream's world I
Ice_cream’s world I
ice_cream’s world is a rich country, it has many fertile lands. Today, the queen of ice_cream wants award land to diligent ACMers. So there are some watchtowers are set up, and wall between watchtowers be build, in order to partition the ice_cream’s world. But how many ACMers at most can be awarded by the queen is a big problem. One wall-surrounded land must be given to only one ACMer and no walls are crossed, if you can help the queen solve this problem, you will be get a land.
Input
In the case, first two integers N, M (N<=1000, M<=10000) is represent the number of watchtower and the number of wall. The watchtower numbered from 0 to N-1. Next following M lines, every line contain two integers A, B mean between A and B has a wall(A and B are distinct). Terminate by end of file.
Output
Output the maximum number of ACMers who will be awarded.
One answer one line.
Sample Input
8 10
0 1
1 2
1 3
2 4
3 4
0 5
5 6
6 7
3 6
4 7
Sample Output
3
题意:构成了几个环。
题解:
void mix(int a,int b)
{
int x;
int y;
x=find(a);
y=find(b);
if(x!=y)
road[x]=y;
else
ans++;
}
这里这样写就OK
#include<stdio.h>
int road[1010];
int ans;
int find(int a)
{
if(road[a]==a) return a;
else
return find(road[a]);
}
void mix(int a,int b)
{
int x;
int y;
x=find(a);
y=find(b);
if(x!=y)
road[x]=y;
else
ans++;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
ans=0;
for(int i=0;i<=n-1;i++)
road[i]=i;
int a, b;
for(int i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
mix(a,b);
}
printf("%d\n",ans);
}
}
HDOJ 2120 Ice_cream's world I的更多相关文章
- hdoj 2120 Ice_cream's world I【求成环数】
Ice_cream's world I Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 2120 Ice_cream's world I
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2120 Ice_cream's world I Description ice_cream's worl ...
- hdoj 2121 Ice_cream’s world II 【没有最低树的根节点】
称号:pid=2121" target="_blank">hdoj 2121 Ice_cream's world II 题意:题目是一道躶题,给n个点,m条边的有向 ...
- hdoj 2122 Ice_cream’s world III
并查集+最小生成树 Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- HDOJ 2120 并查集
并查集的应用,用来查找被分割的区域个数. 即当两个节点值相同时说明已经为了一个圈,否则不可能,此时区域个数加1. #include<iostream> #include<cstdio ...
- HDU 2120 Ice_cream's world I(并检查集合)
职务地址:HDU 2120 这题尽管字数不多,但就是看不懂. . 意思是求最多有多少个被墙围起来的区域.显然就是求环的个数.然后用并查集求环个数就能够了. 代码例如以下: #include <i ...
- 杭电 2120 Ice_cream's world I (并查集求环数)
Description ice_cream's world is a rich country, it has many fertile lands. Today, the queen of ice_ ...
- HDU 2120 Ice_cream's world I【并查集】
解题思路:给出n对点的关系,求构成多少个环,如果对于点x和点y,它们本身就有一堵墙,即为它们本身就相连,如果find(x)=find(y),说明它们的根节点相同,它们之间肯定有直接或间接的相连,即形成 ...
- hdoj 2122 Ice_cream’s world III【最小生成树】
Ice_cream's world III Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- c# string.format 的简写 $
var name = "huchao"; var info = $"你是谁,我叫:{name}"; Console.Write(info); Console.R ...
- agc015F - Kenus the Ancient Greek(结论题)
题意 题目链接 $Q$组询问,每次给出$[x, y]$,定义$f(x, y)$为计算$(x, y)$的最大公约数需要的步数,设$i \leqslant x, j \leqslant y$,求$max( ...
- thinkphp搜索实现
视图: <html lang="zh-cn"><head> <meta charset="UTF-8"><title& ...
- unicode字符和多字节字符的相互转换接口
作者:朱金灿 来源:http://blog.csdn.net/clever101 发现开源代码的可利用资源真多,从sqlite3的源码中抠出了几个字符转换接口,稍微改造下了发现还挺好用的.下面是实现代 ...
- 时序js插件cubism使用
document http://iwantmyreal.name/blog/2012/09/16/visualising-conair-data-with-cubism-dot-js https:// ...
- java Vamei快速教程21 事件响应
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在GUI中,我们看到了如何用图形树来组织一个图形界面.然而,这样的图形界面是静态的 ...
- 300行ABAP代码实现一个最简单的区块链原型
不知从什么时候起,区块链在网上一下子就火了. 这里Jerry就不班门弄斧了,网上有太多的区块链介绍文章.我的这篇文章没有任何高大上的术语,就是300行ABAP代码,实现一个最简单的区块链原型. 我个人 ...
- ES6中set和map的区别
Set ES6提供了新的数据结构Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set函数可以接受一个数组(或类似数组的对象)作为参数,用来初始化. // 例一 var set = ne ...
- Python风格规范-FYI
Python风格规范 分号 Tip 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 行长度 Tip 每行不超过80个字符 例外: 长的导入模块语句 注释里的URL 不要使用反斜杠连接行. Py ...
- 安装git 配置邮箱和用户名
git 查看用户名和邮箱地址 $ git config user.email $ git config user.name 运行命令来配置你的用户名和邮箱 $ git config --global ...