HDU 2120 Ice_cream's world I
2016-03-28 19:13
495 查看
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
Sample Output
原谅我其实看不懂题。
题意:问在一个图中,有几个环;(应该是这样)
小希同学那道题中判断环的思想,直接ans++;
AC代码:
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 34 0 5 5 6 6 7 36 4 7
Sample Output
3
原谅我其实看不懂题。
题意:问在一个图中,有几个环;(应该是这样)
小希同学那道题中判断环的思想,直接ans++;
AC代码:
#include <bits/stdc++.h> using namespace std ; int n , m , pre[2000],vis[2000],ans; int find ( int x ) { if(x!=pre[x]) return pre[x]=find(pre[x]); return x ; } void mix(int x , int y ) { int dx = find(x); int dy = find(y); if(dx!=dy) { pre[dy]=dx; } else ans++; } int main() { while(cin>>n>>m) { ans = 0 ; for(int i = 0 ; i<n;i++) { vis[i]=0; pre[i]=i; } for(int i= 0 ; i < m ; i++) { int a , b ; cin>>a>>b; mix(a,b); } cout<<ans<<endl; } return 0 ; }
相关文章推荐
- 非阻塞connect的实现
- matlab使用摄像头
- C#多态
- C#进阶系列——WebApi身份认证解决方案:Basic基础认证 (转)
- 【NOIP2013提高组day2】华容道
- Ubuntu下安装和卸载qt***.run格式的程序
- 系统安装----内核编译
- CGI跟我学
- VC++开发简易输电线路管理信息系统
- 线性回归
- JavaScript match() 方法
- SpringMVC拦截器(资源和权限管理)
- 如何正确的配置百度地图访问应用key
- 作业4.2
- Android下的Dialog
- http://xss.heimaoseoer.com/TIqiri?1413093855
- 拥抱 Android Studio 之五:Gradle 插件开发
- aapt命令说明
- BZOJ-3083 遥远的国度 树链剖分+分类讨论 or DFS序
- 基于DFS的求割点算法