POJ1325 Machine Schedule 【二分图最小顶点覆盖】
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 11958 | Accepted: 5094 |
Description
we consider a 2-machine scheduling problem.
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
x, y.
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
Source
题意:二分图最小覆盖:找到一个点集,使得每条边上至少有一个点在该集合中。最小匹配==最大覆盖。
题解:匈牙利,因为问的是机器重新启动次数,所以对于左右连接点有0号模式的任务不要读入图中。
#include <stdio.h>
#include <string.h> const int inf = 0x3f3f3f3f;
const int maxn = 102;
int n, m, k;
bool map[maxn][maxn], visy[maxn];
int cx[maxn], cy[maxn]; void getMap() {
memset(map, 0, sizeof(map));
int u, v;
while(k--) {
scanf("%*d%d%d", &u, &v);
if(u * v) map[u][v] = true;
}
} int findPath(int x) {
int i, j;
for(i = 0; i < m; ++i) {
if(map[x][i] && !visy[i]) {
visy[i] = 1;
if(cy[i] == -1 || findPath(cy[i])) {
cx[x] = i; cy[i] = x; return 1;
}
}
}
return 0;
} int MaxMatch() {
memset(cy, -1, sizeof(cy));
memset(cx, -1, sizeof(cx));
int i, j, ans = 0;
for(i = 0; i < n; ++i) {
if(cx[i] == -1) {
memset(visy, 0, sizeof(visy));
ans += findPath(i);
}
}
return ans;
} void solve() {
printf("%d\n", MaxMatch());
} int main() {
// freopen("stdin.txt", "r", stdin);
while(scanf("%d%d%d", &n, &m, &k) == 3) {
getMap();
solve();
}
return 0;
}
POJ1325 Machine Schedule 【二分图最小顶点覆盖】的更多相关文章
- [poj1325] Machine Schedule (二分图最小点覆盖)
传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...
- UVA1194 Machine Schedule[二分图最小点覆盖]
题意翻译 有两台机器 A,B 分别有 n,m 种模式. 现在有 k 个任务.对于每个任务 i ,给定两个整数$ a_i\(和\) b_i$,表示如果该任务在 A上执行,需要设置模式为 \(a_i\): ...
- POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题
POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...
- HDU 1150 Machine Schedule (二分图最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...
- POJ - 1325 Machine Schedule 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
- POJ1325 Machine Schedule(二分图最小点覆盖集)
最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- poj3041 Asteroids(二分图最小顶点覆盖、二分图匹配)
Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...
- ZOJ 1364 Machine Schedule(二分图最大匹配)
题意 机器调度问题 有两个机器A,B A有n种工作模式0...n-1 B有m种工作模式0...m-1 然后又k个任务要做 每一个任务能够用A机器的模式i或b机器的模式j来完毕 机器開始都处于模式0 每 ...
随机推荐
- VC调用javascript的几种方法
第一种:通过execScript调用.这种方法,虽然操作方便,但不能获取返回值.m_spHtmlDoc->get_parentWindow(&m_pHtmlWindow);VARIANT ...
- uva156 By sixleaves
1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 #include <ma ...
- 微软已于10月底停止销售预装Windows 7/8.1的电脑
如果你想买新电脑,但是对Windows 10不感冒,你最好抓紧时间,因为这个月底是Windows7和Windows8.1的最后销售期限.10月31号是你能买到预装这两款操作系统的新电脑的最后一天,微软 ...
- 奇妙的算法之LCS妙解
LCS算法妙解 LCS问题简述:最长公共子序列 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则S 称为已知序列的最长公共子序列. LCS问题的分支:最长公共子串 ...
- how to translate the text of push button
Background:In a project, the need to translate the buttons on the screen, as shown below,the followi ...
- 你知道为什么Xcode6中Swift没有智能提示和自己主动补全功能吗 ?
你知道为什么Xcode6中Swift没有智能提示和自己主动补全功能吗 ? 长沙戴维营教育将为你解开这个巨大的谜团大BUG! http://www.ubuntucollege.cn/course/29/ ...
- 【枚举+小技巧】【TOJ4115】【Find the number】
题目大意 找到一个最小的奇数 约数个数为n 结果mod10^9+7 根据 约数个数=(p1+1)*(p2+1)............ 将n 枚举分解成连乘式.(枚举个数,dfs) 比较大小 log ...
- VIM 中 查看{}是否闭合,按%跳转到下个闭合
VIM 中 查看{}是否闭合,按%跳转到下个闭合
- jQuery基础---Ajax基础教程(二)
jQuery基础---Ajax进阶 内容提纲: 1.加载请求 2.错误处理 3.请求全局事件 4.JSON 和 JSONP 5.jqXHR 对象 发文不易,转载请注明出处! 在 Ajax 基础一篇中, ...
- Oracle 启用块跟踪
Oracle 启用块跟踪,语法示例如下: alter database enable block change tracking using file '/u01/app/oracle/oradata ...