hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版

时间:2022-12-18 12:10:12

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

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

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

 //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&lpar;最小顶点覆盖&rpar;

    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 &lpar;二分匹配&rpar;

    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. 二分图最大匹配(匈牙利算法)简介&amp&semi; Example hdu 1150 Machine Schedule

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

  9. HDU 1150 Machine Schedule &lpar;二分图最小点覆盖&rpar;

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

随机推荐

  1. phalcon&colon; update修改数据却变成了insert插入数据

    phalcon: 在对表进行操作是,update修改数据却变成了insert插入数据. 发现,update的时,无论怎么加where都会变成了insert插入数据. 检查了一下表,原来是表没有 主键引 ...

  2. 后半部分样式和JS前半部分脚本语言

    样式 剩余样式: 1.<div style=display:"none"></div>:nono 是隐藏该元素内容,block是显示该元素内容 2.< ...

  3. 命令学习:iftop

    iftop显示带宽使用情况 http://riobard.com/2010/04/30/l2tp-over-ipsec-ubuntu/ http://jaseywang.me/2011/12/19/i ...

  4. archlinux的wiki非常强壮

    最近发现搜索linux工具或系统配置内容.来自同一个站点很多很好的资源:https://www.archlinux.org/,网站wiki(https://wiki.archlinux.org/)中有 ...

  5. 聊聊VUE中的nextTick

    在谈nextTick之前,先要说明一件事,可能在我们平时使用vue时并没有关注到,事实上,vue执行的DOM更新是异步的. 举个栗子: <template> <div class=& ...

  6. 对于一个刚入门的linux运维来说

    干 就完了~ 我觉得 人生的意义在于 不断地学习......

  7. HDU&sol;HDOJ 4699 Editor

    对顶栈算法. 此题充分说明了cin的不中以及scanf的优越性. 我TM用cin超时了!!!换成scanf就A了!!! #include <cstdio> #include <cst ...

  8. 剑指Offer&lowbar;编程题&lowbar;10

    题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? class Solution { public: int r ...

  9. python3处理json数据

    获取actuator的值 [root@mongo_rs1 tmp]# cat test.py import requests import json url = 'http://wxtest.mayo ...

  10. weblogic创建域生产模式,输入用户名闪退

    weblogic创建域,生产模式,报错 <2017-12-29 下午04时53分59秒 CST> <Info> <Security> <BEA-090065& ...