//两道大水……哦不 两道结论题

结论:二部图的最小覆盖数=二部图的最大匹配数

有向图的最小覆盖数=节点数-二部图的最大匹配数

 //hdu 1150
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string> using namespace std; int n,m,k;
int f[][];
int link[];
bool adj[];
bool used[]; bool work(int x){
for (int i=;i<m;i++){
if (f[x][i] && adj[i]==false){
adj[i]=true;
if (!used[i] || work(link[i])){
link[i]=x;
used[i]=;
//printf("%d %d\n",x,i);
return true;
}
}
}
return false;
} int main(){
while (scanf("%d%d%d",&n,&m,&k)==){
memset(f,,sizeof(f));
memset(used,,sizeof(used));
for (int i=;i<k;i++){
int x,y,z;
scanf("%d%d%d",&z,&x,&y);
if (x!= && y!=){
f[x][y]=;
}
}
int ans=;
for (int i=;i<n;i++){
memset(adj,,sizeof(adj));
if (work(i)) ans++;
}
//for (int i=1;i<m;i++) printf("%d %d\n",i,link[i]);
printf("%d\n",ans);
}
return ;
}
/*
5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0
*/
 //hdu 1151
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string> using namespace std; int T;
int n,m;
bool f[][];
int link[];
bool adj[];
bool used[]; bool work(int x){
for (int i=;i<=n;i++){
if (f[x][i] && !adj[i]){
adj[i]=;
if (!used[i] || work(i)){
link[i]=x;
used[i]=;
return true;
}
}
}
return false;
} int main(){
scanf("%d",&T);
for (int cas=;cas<=T;cas++){
memset(used,,sizeof(used));
memset(link,,sizeof(link));
memset(f,,sizeof(f));
scanf("%d",&n);
scanf("%d",&m);
for (int i=;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
f[x][y]=;
}
int ans=n;
for (int i=;i<=n;i++){
memset(adj,,sizeof(adj));
if (work(i)) ans--;
}
printf("%d\n",ans);
}
return ;
}
/*
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
*/

hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版的更多相关文章

  1. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

  2. hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...

  3. hdu 1150 Machine Schedule(最小顶点覆盖)

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  4. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  5. hdu 1150 Machine Schedule 最少点覆盖

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  6. hdu 1150 Machine Schedule (二分匹配)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU——1150 Machine Schedule

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule

    二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...

  9. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

随机推荐

  1. Linux下的摄影后期处理软件

    由于喜欢摄影,在LInux上折腾,想找一款能代替lightroom的软件.发现darktable这款软件专业.于是就安装了. 以下是在Linux上安装darktable的instruction,需要添 ...

  2. 转:SCHEME 语言是怎么来的 -1

    导言 Scheme 是 LISP 的一个方言(dialect).著名的 SICP 书就是以 Scheme 为教学语言(实际上 SICP 的作者就是 Scheme 的作者). 虽然 Scheme 本身只 ...

  3. 【转】 linux内核移植和网卡驱动(二)

    原文网址:http://blog.chinaunix.net/uid-29589379-id-4708911.html 一,内核移植步骤: 1, 修改顶层目录下的Makefile ARCH       ...

  4. kindeditor在sae上传文件修改,适合php

    kindeditor在sae上传文件修改,适合php 当前位置: 首页  > 论坛  > 经验共享 用户登录   新用户注册   主题: kindeditor在sae上传文件修改,适合ph ...

  5. iOS 10 的一些变化

    原文链接:http://www.jianshu.com/p/9756992a35ca

  6. vb.NET基础总结

    vb.NET语言的学习,相对于原来的添加了.net平台,也 是基于对vb学习的继承与扩展,是在面向对象基础上的编程语言,vb中学到的控制语句,主要的数据类型,对象的事件,方法,属性等继续应用于vb.n ...

  7. js操作iframe框架时应该屡清楚的一些概念

    1.获取iframe的window对象 存在跨域访问限制. iframeElement.contentWindow 兼容 2.获取iframe的document对象 存在跨域访问限制. chrome: ...

  8. Sql语句之查询所有学生所有科目分数及总分

    昨天练Sql语句,数据库建了四个表分别是,学生表,课程表,成绩表以及教师表(教师表不在讨论范围),突然想到以前高中时代老师手上的那张成绩表,然后我就寻思着能不能用Sql语句把表打印出来,以下是我的思考 ...

  9. 详解AJAX核心 —— XMLHttpRequest 对象 (上)

    我要说的内容都是非常基础的内容,高手就免看了,如果看了欢迎给点意见啊.新手或者对低层还不是很了解的人可以看看,帮助理解与记忆. XMLHttpRequest 对象是AJAX功能的核心,要开发AJAX程 ...

  10. MVC 授权过滤器 AuthorizeAttribute

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...