HDU 2120 Ice_cream's world I(并查集,环的个数,冰激凌王国有什么?)
来源:互联网 发布:淘宝试用中心在哪儿 编辑:程序博客网 时间:2024/05/05 20:09
Ice_cream's world I(题目)
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1254 Accepted Submission(s): 750
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.
One answer one line.
Sample Input
8 100 11 21 32 43 40 55 66 73 64 7
Sample Output
3
Author
Wiskey
Source
HDU 2007-10 Programming Contest_WarmUp
题意:
这翻译也是够了,大意就是女王分土地的问题吧。(有道翻译的没明白)直接过思路吧。
思路:
想到判断有几个环在图中,这个题目就迎刃而解了。
代码:
#include<stdio.h>#define MYDD 10000int pre[MYDD];void init(int x) {for(int j=0; j<x; j++)pre[j]=j;}int find(int x) {//根节点查找函数 return x==pre[x]? x:find(pre[x]);}bool combine(int x,int y) {//判断是否成环int fx=find(x);int fy=find(y);if(fx==fy)//根节点相同,成环return true;else {pre[fx]=fy;return false;}}int main() {int n,m;while(scanf("%d%d",&n,&m)!=EOF) {init(n);//初始化 int ans=0;while(m--) {int a,b;scanf("%d%d",&a,&b);if(combine(a,b))//成环 ans++;}printf("%d\n",ans);}return 0;}
后:
别人一分钟学会的,你花十分钟掌握也行,不怕走得慢,就怕怠慢。
***********************************************************************************
0 0
- HDU 2120 Ice_cream's world I(并查集,环的个数,冰激凌王国有什么?)
- HDU:2120 Ice_cream's world I(并查集+统计环的个数)
- hdu 2120 Ice_cream's world I(判断是否有环,简单的并查集)
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】
- HDU 2120 Ice_cream's world I(并查集)
- hdu 2120 Ice_cream's world I 并查集
- HDU 2120 Ice_cream's world I 并查集
- HDU-2120-Ice_cream's world I【并查集】
- hdu 2120 Ice_cream's world I (简单并查集 + 判环)
- 【HDU】-2120-Ice_cream's world I(并查集,环)
- hdu2120 Ice_cream's world I (并查集查找环的个数)
- hdu2120 Ice_cream's world I (并查集查找环的个数)
- HDOJ 2120 Ice_cream's world I(并查集)
- HDOJ 2120 Ice_cream's world I(并查集)
- Ice_cream's world I hdu 2120 并查集判断环
- HDU Problem 2120 Ice_cream's world I 【并查集检查环】
- hdoj--2120--Ice_cream's world I(并查集判断环)
- 强连通分量 ( Tarjan,邻接链表 )——The Bottom of a Graph ( POJ 2553 )
- Windows操作系统产品名与内部版本号的对应
- js对文字的修饰 big() small() fixed() toUpperCase() toLowerCase()
- 杭电-4707 Pet
- [LeetCode] 70. Climbing Stairs
- HDU 2120 Ice_cream's world I(并查集,环的个数,冰激凌王国有什么?)
- 最长回文字串-Manacher解法
- 问题:jquery event.which详解
- 可是姑娘,你为什么要编程呢?
- 阴影
- SQLi Labs Lesson4
- DatabaseMetaData中getTables获取数据库所有表(查表)
- 问题:The value for the useBean class attribute com.packageName.className is invalid.
- String.fromCharCode()函数