Machine Schedule(二分图匹配之最小覆盖点,匈牙利算法)
个人心得:二分图啥的一点都不知道,上网借鉴了下,请参考http://blog.csdn.net/thundermrbird/article/details/52231639
加上自己的了解,二分图就是将图形拆分成俩半,俩边的点通过边界相连接。匹配就是不存在俩条边存在同一顶点,就是一个顶点最多连接一条边。
匈牙利算法就是用增广路进行更新,仔细一想确实如此,如果存在这样的途径那么必然可以用亦或就行维护更新,细节看参考。
不过碍于自己图论太low,还是无法运用的好,比如这题,就是最小覆盖点,关于最小覆盖点等于最大匹配数还没搞明白。
总的来说这就是给我提供一个二分最大匹配的模板吧,算法细节方面有时间还是要去学的,不能单纯为了做题而学习算法!
励志语:没什么能够打倒你,能打倒你的只有你的自卑和懦弱。前方大路终究变得宽阔,加油。
题目:
There are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1, ..., mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1, ... , mode_m-1. At the beginning they are both work at mode_0.
For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode_3 or in machine B at mode_4, job 1 can either be processed in machine A at mode_2 or in machine B at mode_4, and so on. Thus, for job i, the constraint can be represent as a triple (i, x, y), which means it can be processed either in machine A at mode_x, or in machine B at mode_y.
Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the times of restarting machines.
Input
The input will be terminated by a line containing a single zero.
Output
Sample Input
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
Sample Output
3
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxa=;
int g[maxa][maxa];
int book[maxa];
int link[maxa];
int n,m,k;
int dfs(int u){
int v;
for(v=;v<m;v++)
if(g[u][v]&&!book[v])
{
book[v]=;
if(link[v]==-||dfs(link[v]))
{
link[v]=u;
return ;
}
}
return ;
}
int hungary()
{
int res=;
int u;
memset(link,-,sizeof(link));
for(int i=;i<n;i++)
{
memset(book,,sizeof(book));
if(dfs(i)) res++;
}
return res;
}
int main(){
while(cin>>n){
if(n==) break;
memset(g,,sizeof(g));
cin>>m>>k;
int x,y,z;
while(k--){
cin>>x>>y>>z;
if(y>&&z>) g[y][z]=;
}
cout<<hungary()<<endl; } return ;
}
Machine Schedule(二分图匹配之最小覆盖点,匈牙利算法)的更多相关文章
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题
POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...
- HDU 1150 Machine Schedule (最小覆盖,匈牙利算法)
题意: 有两台不同机器A和B,他们分别拥有各种运行模式1~n和1~m.现有一些job,需要在某模式下才能完成,job1在A和B上需要的工作模式又可能会不一样.两台机器一开始处于0模式,可以切换模式,但 ...
- ZOJ 1364 Machine Schedule(二分图最大匹配)
题意 机器调度问题 有两个机器A,B A有n种工作模式0...n-1 B有m种工作模式0...m-1 然后又k个任务要做 每一个任务能够用A机器的模式i或b机器的模式j来完毕 机器開始都处于模式0 每 ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- hdu 1150 Machine Schedule (二分匹配)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- UVA 1663 Purifying Machine (二分图匹配,最大流)
题意: 给m个长度为n的模板串,模板串由0和1和*三种组成,且每串至多1个*,代表可0可1.模板串至多匹配2个串,即*号改成0和1,如果没有*号则只能匹配自己.问:模板串可以缩减为几个,同样可以匹配原 ...
- hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)
Problem Description Thanks to a certain "green" resources company, there is a new profitab ...
- HDU1150 Machine Schedule(二分图最大匹配、最小点覆盖)
As we all know, machine scheduling is a very classical problem in computer science and has been stud ...
随机推荐
- iView--3
项目基本结构 简单介绍目录 build目录是一些webpack的文件,配置参数什么的,一般不用config是vue项目的基本配置文件node_modules是项目中安装的依赖模块src源码文件夹,基本 ...
- RedLock 实现分布式锁
J并发是程序开发中不可避免的问题,根据系统面向用户.功能场景的不同,并发的重视程度会有不同.从程序的角度来说,并发意味着相同的时间点执行了相同的代码,而有些情况是不被允许的,比如:转账.抢购占库存等, ...
- 利用hash构建HTML切换
在Web App和Hybrid App横行的时代,为了拥有更好的用户体验,单页面应用顺势而生,单页面应用简称`SPA`,即Single Page Application,就是只有一个HTML页面的应用 ...
- photoshop CS5制作具有立体感的按钮
今天在学习用photoshop cs5制作html模板的过程中,遇到了立体感按钮的制作问题.当然按钮的立体感也可以用CSS来实现,这里主要是用PS来制作具有立体感的按钮. 我也是PS新手,下面的东西, ...
- WebAPI项目 IHttpActionResult不识别解决办法
转自:http://blog.csdn.net/nnnnnbody/article/details/16945253 使用ASP.NET Web API构造基于restful风格web service ...
- 使用jenkins自动构建docker容器范例
1.登录Jenkins,新建一个自由风格的软件项目. 2.源码管理选择git,并添加Repository URL.Credentials 3.构建选择 Execute Shell,命令如下: dock ...
- MVC,MVVM,MVP等设计模式的分析
从Script到Code Blocks.Code Behind到MVC.MVP.MVVM 三个模式按照大致的历史进程将这些概念进行划分: Script Code Blocks.Code Behind ...
- python3.6环境部署文档
python3.6环境部署文档 内容 Linux部署Python3.6环境 Mac部署Python3.6环境 Window10部署Python3.6环境 Pycharm安装 1. Linux部署P ...
- [转载]java获取word里面的文本
需求场景 开发的web办公系统如果需要处理大量的Word文档(比如有成千上万个文档),用户一定提出查找包含某些关键字的文档的需求,这就要求能够读取 word 中的文字内容,而忽略其中的文字样式.表格. ...
- eclipse安装插件:
eclipse安装插件:jre跟eclipse的bit数必须匹配,即必须都是32or64位的 历史版本不好找,pydev的历史版本在sourceforge中很隐蔽,得在项目的activite中查找,另 ...