Machine Schedule
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 11958   Accepted: 5094

Description

As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here
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

The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i,
x, y. 



The input will be terminated by a line containing a single zero. 

Output

The output should be one integer per line, which means the minimal times of restarting machine.

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 【二分图最小顶点覆盖】的更多相关文章

  1. [poj1325] Machine Schedule (二分图最小点覆盖)

    传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...

  2. UVA1194 Machine Schedule[二分图最小点覆盖]

    题意翻译 有两台机器 A,B 分别有 n,m 种模式. 现在有 k 个任务.对于每个任务 i ,给定两个整数$ a_i\(和\) b_i$,表示如果该任务在 A上执行,需要设置模式为 \(a_i\): ...

  3. POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题

    POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...

  4. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

  5. POJ - 1325 Machine Schedule 二分图 最小点覆盖

    题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...

  6. POJ1325 Machine Schedule(二分图最小点覆盖集)

    最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...

  7. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

  8. poj3041 Asteroids(二分图最小顶点覆盖、二分图匹配)

    Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...

  9. ZOJ 1364 Machine Schedule(二分图最大匹配)

    题意 机器调度问题 有两个机器A,B A有n种工作模式0...n-1 B有m种工作模式0...m-1 然后又k个任务要做 每一个任务能够用A机器的模式i或b机器的模式j来完毕 机器開始都处于模式0 每 ...

随机推荐

  1. poj 1157 LITTLE SHOP_简单dp

    题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...

  2. [置顶] 获取系统时间的方法--linux

    一. localtime 函数获取(年/月/日/时/分/秒)数值. 1.感性认识 #include<time.h>     //C语言的头文件 #include<stdio.h> ...

  3. 网易云课堂_Linux操作系统入门(嵌入式开发零基础Ⅰ)_章节4:SHELL 环境

    课时44命令别名 命令别名 命令别名的概念: 命令别名的查看:alias 命令别名的设置:alias myls='ls -a' 课时45通配符 通配符 通配符都概念: 通配符是代表字符通用匹配的一种系 ...

  4. cf公式专场-续

    Benches Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  5. 使用View Model从表现层分离领域模型

    本文来自:http://www.cnblogs.com/shanyou/archive/2010/04/03/1703501.html Model-View-Controller(模型-视图-控制器, ...

  6. Activity(二)

    多个Activity之间的调用 建立一个Activity 配置layout文件夹下fragment_main.xml文件 在layout下新建other.xml文件 xml文件创建的id需要编译才能生 ...

  7. JeeSite 企业信息化快速开发平台

    平台简介 JeeSite是基于多个优秀的开源项目,高度整合封装而成的高效,高性能,强安全性的开源Java EE快速开发平台. JeeSite本身是以Spring Framework为核心容器,Spri ...

  8. HTML5 canvas 绘制精美的图形

    HTML5 是一个新兴标准,它正在以越来越快的速度替代久经考验的 HTML4.HTML5 是一个 W3C “工作草案” — 意味着它仍然处于开发阶段 — 它包含丰富的元素和属性,它们都支持现行的 HT ...

  9. 解决aapt命令在Linux下无法运行的问题

    新的一个项目,需要在Linux下执行aapt命令对apk文件进行处理 开发环境: MacBook-Pro:appSecuity zhang$ uname -a Darwin huijundeMacBo ...

  10. WebView的基本使用

    ---恢复内容开始--- 一.实例化WebView 通过xml实例化 xml <WebView android:id="@+id/webview" android:layou ...