题意:有两台机器A和B,A有n种工作模式(0~n-1),B有m种工作模式(0~m-1),两台机器的初始状态都是在工作模式0处。现在有k(0~k-1)个工作,(i,x,y)表示编号为i的工作可以通过机器A的工作模式x完成,也可以通过机器B的工作模式y完成。机器必须重启后才能更换一种工作模式,问最少的重启次数。

分析:

1、重启次数最少,即工作模式种类最少,即用最少的工作模式完成所有工作。

2、将A的n种工作模式看做n个点,将B的m种工作模式看做m个点,即用最少的点(工作模式)覆盖所有的边(一条边代表一种工作)。

3、最小点覆盖数 = 最大匹配数。

最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联;---实质上是能覆盖所有的边的最小点集。

4、注意,因为两台机器的初始状态都是在工作模式0处,因此若一条边的其中一个端点为0,则可以将其看做是在两台机器的初始工作状态时完成的,即不参与重启次数的统计。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 1000000 + 10;
using namespace std;
int n, m, k;
int vis[MAXN];
bool used[MAXN];
int pic[110][110];
void init(){
memset(pic, 0, sizeof pic);
memset(vis, 0, sizeof vis);
}
bool dfs(int x){
for(int i = 1; i < m; ++i){
if(pic[x][i] && !used[i]){
used[i] = true;
if(!vis[i] || dfs(vis[i])){
vis[i] = x;
return true;
}
}
}
return false;
}
int hungary(){
int cnt = 0;
for(int i = 1; i < n; ++i){
memset(used, false, sizeof used);
if(dfs(i)) ++cnt;
}
return cnt;
}
int main(){
while(scanf("%d", &n) == 1){
if(!n) return 0;
init();
scanf("%d%d", &m, &k);
for(int i = 0; i < k; ++i){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if(b > 0 && c > 0) pic[b][c] = 1;
}
printf("%d\n", hungary());
}
return 0;
}

  

HDU - 1150 Machine Schedule(二分匹配---最小点覆盖)的更多相关文章

  1. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

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

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

  3. (step6.3.3)hdu 1150(Machine Schedule——二分图的最小点覆盖数)

    题目大意:第一行输入3个整数n,m,k.分别表示女生数(A机器数),男生数(B机器数),以及它们之间可能的组合(任务数). 在接下来的k行中,每行有3个整数c,a,b.表示任务c可以有机器A的a状态或 ...

  4. POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题

    POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...

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

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

  6. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

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

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

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

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

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

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

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

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

随机推荐

  1. 弱点扫描-openvas初始化

    OPENVAS: NESSUS项目分支:商业版的扫描器 管理目标系统的漏洞 免费开源 Kali 默认安装但是未配置个启动 安装 创建证书 同步弱点数据库 创建客户端证书 重建数据库 备份数据库 启动服 ...

  2. 06.swoole学习笔记--异步tcp服务器

    <?php //创建tcp服务器 $host='0.0.0.0'; $port=; $serv=new swoole_server($host,$port); //设置异步进程工作数 $serv ...

  3. 014、MySQL取本月天数(这个月有多少天)

    #取本月天数 SELECT DATEDIFF( date_add( curdate( ) , INTERVAL MONTH ), DATE_ADD( curdate( ), INTERVAL DAY ...

  4. 利用jQuery实现PC端href生效,移动端href失效

    今天要写一个功能,记录一下吧.if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){ $('.item-a').attr('href' ...

  5. mysql concat与concat_ws区别

    select concat('大','小') as size from 表 查询出结果为:大小 select concat('大',NULL) as size from 表 查询出结果为:null c ...

  6. 整合 nginx php-fpm

    start 继上一篇 整合两个images  完成 LNMP github  https://github.com/shiphp/nginx-env     稍加修改 vim   dockerfile ...

  7. use matplotlib to draw scatter plot

    There are many pionts in this kind of table. How to do it? We can use scatter() to draw it. Code: im ...

  8. liunx笔记

    Zolertia IPv6/6LoWPAN Ubidots client Son Han Border Router with Raspberry Pi for LLN with TelosBs Co ...

  9. 7 —— node —— 响应图片

      const http = require('http'); const fs = require('fs'); const server = http.createServer(); server ...

  10. iphone 面试题(转)

    转]iPhone 面试题解答 2011-07-20 0:51 转载自  492437598 最终编辑  492437598 1.main()  {     int a[5]={1,2,3,4,5};  ...