hdu 1068 Girls and Boys 匈牙利
来源:互联网 发布:linux查询文件大小 编辑:程序博客网 时间:2024/05/21 00:00
题目 http://acm.hdu.edu.cn/showproblem.php?pid=1068
题意求出男孩和女孩没有暧昧关系的人数哦 刚开始错了数组开的太大了 超内存了。。。
这个是先求出最大匹配数 再用总的人数减掉就是答案了
思路:
最大独立集点数 = N - 最大匹配数
具体代码是
#include<iostream>#include<cstring>#include<cstdio>using namespace std;#define max 1000bool map[max][max];bool mark[max];int n;int cx[max],cy[max],link[max];int findpath(int u) //找增广路径{ int i,j; for(i=0;i<n;i++) { if(map[u][i]&&!mark[i]) { mark[i]=1; if(!link[i]||findpath(link[i])) { link[i]=u; return 1; } } } return 0;}void maxmatch() //最大匹配{ int i,j,res=0; for(i=0;i<n;i++) { memset(mark,false,sizeof(mark)); res+=findpath(i); } cout<<n-res/2<<endl; //最大独立点 注意要除以2哦 因为我吧这个当做一个集合了。}int main(){ int i,j,k,num; char a,b; while(cin>>n) { memset(map,false,sizeof(map)); memset(link,0,sizeof(link)); for(k=0;k<n;k++) { cin>>i>>a>>b>>num>>b; for(i=0;i<num;i++) { cin>>j; map[k][j]=1; } } maxmatch(); } return 0;}
- hdu 1068 Girls and Boys 匈牙利
- 匈牙利算法趣解 暨 HDU 1068 Girls and Boys
- HDU 1068 Girls and Boys(二分匹配--匈牙利算法)
- 【hdu 1068 Girls and Boys 最大独立集数 匈牙利算法 】
- HDU-1068 Girls and Boys
- hdu 1068 Girls and Boys
- hdu 1068 Girls and Boys
- hdu 1068 Girls and Boys
- HDU 1068 Girls and Boys
- hdu 1068 Girls and Boys
- HDU 1068 Girls and Boys
- hdu 1068 Girls and Boys
- HDU 1068Girls and Boys
- HDU 1068 Girls and Boys
- hdu 1068 Girls and Boys
- 【hdu 1068】Girls and Boys
- Girls and Boys HDU
- hdu 1068 boys and girls(最大独立点集 ,匈牙利算法)
- 可读写文件系统jffs2
- C++之自增、自减---面试
- Shell中字符串分割的三种方法
- Inside COM读书笔记-----类厂
- VMware与window共享的文件夹丢失
- hdu 1068 Girls and Boys 匈牙利
- [转]对.net系统架构改造的一点经验和教训
- 剑指offer面试题46求1+2+..+n不能用乘除法和选择循环,多种发散思维方法
- mysql sql 百万级数据库优化方案
- opencv学习心得(一)鼠标响应事件绘制轮廓
- Matlab Figure 图形保存以及 Simulink 中 Scope 窗口坐标标注(label)的设置
- socket阻塞与非阻塞,同步与异步、I/O模型
- rhel6 配置yum源
- 字符驱动之四阻塞IO(等待队列)