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 每 ...
 
随机推荐
- Unix/Linux环境C编程入门教程(27)  内存那些事儿
			
calloc() free() getpagesize() malloc() mmap() munmap()函数介绍 calloc(配置内存空间) 相关函数 malloc,free,realloc,b ...
 - Exception in thread "main" java.io.IOException: Failed to set permissions of path
			
在跑BuildForest的时候,编写了下面的程序: package test.breiman; import org.apache.mahout.classifier.df.mapreduce.Bu ...
 - eclipse ctrl链接设置
			
选择[Window]菜单 Preferences ——>General——>Editors——>Text Editors——>Hyperlinking
 - 高性能浏览器网络(High Performance Browser Networking) 第二章
			
第2章 TCP篇 互联网的核心是两个协议,IP和TCP. IP也叫Internet协议,提供主机到主机的路由和寻址:TCP,传输控制协议,在不可靠的传输通道上提供一个可靠的网络抽象.TCP / IP协 ...
 - 开发板怎样开启telnet服务
			
linux开发板开启telnet服务须要一下几个条件: 1.文件系统支持telnet busybox默认是把telnet和telnetd功能编进去了的,所以这一步一般都省了. 2.挂载devpts 挂 ...
 - 【floyd存字典序路径】【HDU1385】【Minimum Transport Cost】
			
题目大意 求多组i到j的最短路径 并输出字典序最小.... 现在只会floyd的方式 利用dis[i][j] 表示i到j的路径中i 后面的节点 更新是比较dis[i][j] dis[i][k]. 记住 ...
 - GrideView合并列合并序号,隐藏某列按钮
			
合并编号列 /// <summary> /// 合并GridView中某列相同信息的行(单元格) /// </summary> /// <param name=" ...
 - HTML5 canvas 绘制精美的图形
			
HTML5 是一个新兴标准,它正在以越来越快的速度替代久经考验的 HTML4.HTML5 是一个 W3C “工作草案” — 意味着它仍然处于开发阶段 — 它包含丰富的元素和属性,它们都支持现行的 HT ...
 - 利用DreamweaverCS5制作一个含有动态标题的教程
			
DreamweaverCS5怎么制作一个含有动态标题?做一个网页就先要做一个标题,一个好标题会让网页让人印象深刻,有动态的标题会让网页更生动,下面我就介绍一下怎么制作一个含有动态的标题 做一个网页 ...
 - JS函数——作用域
			
一 : 作用域的相关概念 首先看下 变量作用域 的概念:一个变量的作用域是程序源代码中定义这个变量的区域.————————<javascript权威指南>第六版全局变量拥有全局作用域,函数 ...