HDU - 1150 Machine Schedule(二分匹配---最小点覆盖)
题意:有两台机器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(二分匹配---最小点覆盖)的更多相关文章
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- hdu 1150 Machine Schedule (二分匹配)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (step6.3.3)hdu 1150(Machine Schedule——二分图的最小点覆盖数)
题目大意:第一行输入3个整数n,m,k.分别表示女生数(A机器数),男生数(B机器数),以及它们之间可能的组合(任务数). 在接下来的k行中,每行有3个整数c,a,b.表示任务c可以有机器A的a状态或 ...
- POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题
POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...
- 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...
- hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- HDU 1150 Machine Schedule (二分图最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
随机推荐
- SQL state [72000]; error code [1461]; ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值 ; nested exception is java.sql.BatchUpdateException: ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值
本文转自 https://www.cnblogs.com/yingsong/p/5685790.html 原 因:某一个字段本为varchar2(1024),但是实际要插入的值超过varchar2允 ...
- UAC绕过初探
笔者最近在学习UAC绕过的技术,通过对其他师傅的文章进行总结,成功利用DLL劫持绕过了UAC,并且可以以High Mandatory Level来启动进程.在此记录下学习过程,笔者也是初次接触,若各位 ...
- 数据可视化-gojs插件使用技巧总结
随着云计算时代的到来,由于Web技术的快速革新以及为了提供高质量的用户体验,数据可视化成为了前端技术发展的一大方向.为了解决这个问题,现如今涌现了很多优秀的第三方的javascript图形库,比如hi ...
- 剑指offer第12题打印从1到n位数以及大整数加法乘法
字符和数字加减就是字符的ASCII码和数字直接加减. 方法一: 1)在字符串操作中给一个整形数字加(字符0)就是把它转化为字符,当然给一个字符减去(字符0)就可以把它转化为数字了:如果确实是最后 ...
- 06.swoole学习笔记--异步tcp服务器
<?php //创建tcp服务器 $host='0.0.0.0'; $port=; $serv=new swoole_server($host,$port); //设置异步进程工作数 $serv ...
- MyBatis: No MyBatis mapper was found in '[xx.mapper]' package. Please check your configuration
在应用入口加入@MapperScan("com.IBM.XXXXX.dao")
- S7-200 smart 网线下载与调试配置
打开 step microwin 7 smart 软件. 连接PLC 打开 通讯模块 我把电脑的改成了如下 我编写的简单的程序 通过外部一个开关 实现输出的一个 IO 的接通与断开 下载完成程序以后 ...
- Vue - slot-scope="scope" 的意义
<template slot-scope="scope"> <el-button type="primary ...
- Spring-IOC(基于XML配置)
什么是IOC? IOC: Inversion of Control(控制反转). 控制反转:将对象的创建权反转给(交给)Spring. 在使用Spring框架之后,对象的实例不再由调用者来创建,而 是 ...
- 四十七、在SAP中,把功能区块整合成一个函数,通过调用函数的办法使代码简洁明了
一.我们查看上一次的代码,非常之凌乱,大体可以分为以下这几个区块 二.我们把最后的2个部分,用函数的方式来写,写法如下: 三.执行程序,和之前一样 四.输出结果