Ice_cream's world I

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 839    Accepted Submission(s):
488

Problem Description
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
 
注意:这是一个求总共有多少环(环内有节点的不算),我们可以利用判断两节点的根节点是否相同来判断!
 
 
 
 
 #include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 10010
using namespace std; int per[maxn],sum;
void init()
{
int i;
for(i=;i<maxn;i++)
{
per[i]=i;//初始化数组
}
}
int find(int x)//查找根节点
{
int t=x;
while(t!=per[t])
t=per[t];
return t;
}
void join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx==fy)
sum++;//环的个数
else
per[fx]=fy;
}
int main()
{
int a,b,i,m,n;
while(scanf("%d%d",&a,&b)!=EOF)
{
init();
sum=;
for(i=;i<b;i++)
{
scanf("%d%d",&m,&n);
join(m,n);
}
printf("%d\n",sum);
}
return ;
}
 
 

Ice_cream's world I--hdu2120的更多相关文章

  1. 【HDU2120】Ice_cream's world I(并查集基础题)

    查环操作,裸题.一次AC. #include <iostream> #include <cstring> #include <cstdlib> #include & ...

  2. A - Ice_cream’s world III

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

  3. 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 ...

  4. HDU 2121 Ice_cream’s world II 不定根最小树形图

    题目链接: 题目 Ice_cream's world II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  5. 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 ...

  6. hdoj 2122 Ice_cream’s world III

    并查集+最小生成树 Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  7. Ice_cream’s world III--2122

    Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. Ice_cream's world I

    Ice_cream's world I Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  9. Ice_cream’s world III(prime)

    Ice_cream’s world III Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Othe ...

随机推荐

  1. [C++程序设计]用指针变量作函数参数接收数组地址

    #include <iostream> using namespace std; void select_sort(int *p, int n) { int i, j, k; ; i &l ...

  2. LaTeX使用titlesec宏包改变章节编号形式的方法

    1.titleformat宏包命令详解 LaTeX中可以用titlesec宏包中的titleformat命令来改变标题形式: 导入宏包: \usepackage{titlesec} 改变标题的代码如下 ...

  3. python安装第三方包的两种方式

    最近研究QQ空间.微博的(爬虫)模拟登录,发现都涉及RSA算法.于是需要下一个RSA包(第三方包).折腾了很久,主要是感觉网上很多文章对具体要在哪里操作写得不清楚.这里做个总结,以免自己哪天又忘了. ...

  4. New Start!

    博客连续搬了几个地方,从一开始的网易lofter,到点点,再到后来新浪sae自己搭建,折腾了很久,都因为各种原因没有坚持写博. 想了想,其实说到底还是因为懒,根本原因是自己没有毅力.什么不能贴代码,不 ...

  5. python解释器内建函数002

    001.dict 函数来创建字典 #!/usr/bin/python #!coding:utf-8 if __name__ == "__main__": dct001=dict(h ...

  6. [TYVJ] P1055 沙子合并

    沙子合并 描述 Description     设有N堆沙子排成一排,其编号为1,2,3,…,N(N<=300).每堆沙子有一定的数量,可以用一个整数来描述,现在要将这N堆沙子合并成为一堆,每次 ...

  7. 编程修养-C语言篇(二)

    1.版权和版本——————— 好的程序员会给自己的每个函数,每个文件,都注上版权和版本.  对于C/C++的文件,文件头应该有类似这样的注释: /*************************** ...

  8. BZOJ NOI十连测 第一测 T1

    思路:首先考虑t=1的情况,t等于1,那么所有位置的颜色相同,我们不用考虑概率的问题,那么,k+d*x在模d下都相等,我们考虑预处理一个数组s[i][j],代表d为i,起始位置为j的等差数列的和,这个 ...

  9. QTableView使用HTML显示富文本

    对于QTableView中的显示,我们前面介绍过很多种,其中包括:文本.进度条.复选框等,今天我们介绍一下关于富文本的显示. 可能绝大多数小伙伴会通过QAbstractTableModel中的data ...

  10. 使用Qt编写服务器端程序(包括Http传输服务器端)的方法

    使用Qt编写客户端的程序的示例或demo较多,但是编写服务器端程序的demo很少.当然,服务器端的程序一般不需要带界面,这点我们可以理解.不过有些时候我们还是需要使用Qt编写一个简单的测试用的服务器代 ...