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 ...
随机推荐
- Struts2框架学习第三章——Struts2基础
本章要点 — Struts 1框架的基本知识 — 使用Struts 1框架开发Web应用 — WebWork框架的基本知识 — 使用WebWork框架开发Web应用 — 在Eclipse中整合To ...
- switchhosts使用技巧
https://jingyan.baidu.com/article/1974b289a3cfd1f4b0f7744d.html
- 常见HTTP状态(304,)
一.1XX(临时响应) 表示临时响应并需要请求者继续执行操作的状态码. 100(继续) 请求者应当继续提出请求.服务器返回此代码表示:已经收到请求的第一部分,正在等待其余部分. 101(切换协议) 请 ...
- CSS之position体验
目录: 1. position介绍 2. relative 3. position 4. fixed与static 5. 总结 1. position介绍 position最简单的理解就是元素位置的定 ...
- Burpsuite的简单应用-y-Proxy
打开burpsuite:Proxy功能 一.进入Proxy页面,代理设置 将浏览器的代理地址设置一样: 之前没有代理,直接添加,有的话,可以勾选就好了:不同浏览器,设置位置不一致,百度参考 二.执行: ...
- 《高级Web应用程序设计》作业(20170904)
作业1(类型-理论学习,上传ftp,截止日期9月20日) 1.请写出ASP.NET MVC的优点. 2.请写出默认项目模板中以下文件夹或文件的作用.App_Data文件夹.Content文件夹.Con ...
- HDU-2196-树形dp/计算树上固定起点的最长路
Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- C#/JAVA 程序员转GO/GOLANG程序员笔记大全(DAY 06)
----------------------------------------- go 并发 // 注解:go 语言天生为程序并发所设计,可以说go的强项就是在cpu并发上的处理. // go 语言 ...
- Gruntjs提高生产力(四)
思考: 1.grunt以工程为单位安装插件? 如果有新工程就要重新安装插件或者把安装好的插件拷贝过去.这样很麻烦,解决方案是需要用grunt的项目统一放在grunt项目中. 2.每次需要针对项目编写g ...
- centos7 rabbitmq 安装
http://www.rabbitmq.com/install-rpm.html Overview rabbitmq-server is included in Fedora. However, th ...