Problem 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
题目大意:有A,B两种机器,给你三个数n,m,k,分别表示机器A有n中工作模式(编号0 ~ n-1),机器B有m种工作模式(编号0~m-1),共有k个任务,每种任务均可以在机器A,B的一个模式下完成。接下来输入k行,每行三个整数a,b,c,其中,a为任务编号,b表示该任务可在机器A的第b种模式下完成,c表示该任务可在机器B的第c中模式下完成。但机器A,B在变换模式时均需重启,让你完成所有的任务并使机器重启的次数最小。(机器A,B初始时均在第0模式)。
  解题思路:此题是求二分图的最小点覆盖。有以下定理:二分图的点覆盖数 = 匹配数。 建图:把A的n种模式和B的m种模式看做顶点,如果某人可在A的第i个模式和B的第j个模式下完成,则将顶点Ai 和 Bj 之间连一条边。
请看代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std ;
const int MAXN = 105 ;
short g[MAXN][MAXN] ;
bool vis[MAXN] ;
short cx[MAXN] , cy[MAXN] ;
int n , m , k ;
void init()
{
memset(g , 0 , sizeof(g)) ;
memset(cx , -1 , sizeof(cx)) ;
memset(cy , -1 , sizeof(cy)) ;
int i ;
for(i = 0 ; i < k ; i ++)
{
int a , b , c ;
scanf("%d%d%d" , &a , &b ,&c) ;
if(b != 0 && c != 0)
{
g[b][c] = 1 ;
}
}
}
int path(int v)
{
int i ;
for(i = 0 ; i < m ; i ++)
{
if(g[v][i] && !vis[i])
{
vis[i] = 1 ;
if(cy[i] == -1 || path(cy[i]))
{
cy[i] = v ;
cx[v] = i ;
return 1 ;
}
}
}
return 0 ;
}
void solve()
{
int i ;
int ans = 0 ;
for(i = 0 ; i < n ; i ++)
{
if(cx[i] == -1)
{
memset(vis , 0 , sizeof(vis)) ;
if(path(i))
ans ++ ;
}
}
printf("%d\n" , ans) ;
}
int main()
{
while (scanf("%d" , &n) != EOF)
{
if(n == 0)
break ;
scanf("%d%d" , &m , &k) ;
init() ;
solve() ;
}
return 0 ;
}

POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang的更多相关文章

  1. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

  2. hdu 1150 Machine Schedule(最小顶点覆盖)

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  3. hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...

  4. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  5. hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版

    //两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...

  6. hdu 1150 Machine Schedule 最少点覆盖

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  7. HDU——1150 Machine Schedule

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

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

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

  9. hdu 1150 Machine Schedule 最小覆盖点集

    题意:x,y两台机器各在一边,分别有模式x0 x1 x2 ... xn, y0 y1 y2 ... ym, 现在对给定K个任务,每个任务可以用xi模式或者yj模式完成,同时变换一次模式需要重新启动一次 ...

随机推荐

  1. 使用WMI监控进程启动与结束

    需要添加引用System.Management 代码: static void Main(string[] args) { //创建WQL事件查询,监视进程开启 var qCreate = new W ...

  2. C#中指针使用总结

    C#为了类型安全,默认并不支持指针.但是也并不是说C#不支持指针,我们可以使用unsafe关键词,开启不安全代码(unsafe code)开发模式.在不安全模式下,我们可以直接操作内存,这样就可以使用 ...

  3. [转]iOS之浅谈纯代码控制UIViewController视图控制器跳转界面的几种方法

    参考:http://www.mamicode.com/info-detail-469709.html 一.最普通的视图控制器UIViewContoller 一个普通的视图控制器一般只有模态跳转的功能( ...

  4. zzuli oj 1145 有问题的里程表 2

    Description 某辆汽车有一个里程表,该里程表可以显示一个整数,为该车走过的公里数.然而这个里程表有个毛病:它总是从3变到5,而跳过数字4,里程表所有位(个位. 十位.百位等)上的数字都是如此 ...

  5. SQL函数:小写金额转换成大写

    /********************************************************作者:版本:1.0创建时间:20020227修改时间:功能:小写金额转换成大写参数:n ...

  6. MYSQL数据库备份与恢复【转】

    mysqldump -h主机名  -P端口 -u用户名 -p密码 (–database) 数据库名 > 文件名.sql  在window上需要通过CMD进入mysql安装目录下的bin目录下执行 ...

  7. leetcode第三题Longest Substring Without Repeating Characters java

    Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...

  8. 好吧,如果一定要RESTFUL的DJANGO

    看看人家写的VIEWSET, 然后用REQUESTS测试一下. from rest_framework import viewsets from rest_framework.decorators i ...

  9. Performance Test of List<T>, LinkedList<T>, Queue<T>, ConcurrentQueue<T>

    //Test Group 1 { var watch = Stopwatch.StartNew(); var list = new List<int>(); ; j < ; j++) ...

  10. [转贴]一个将表格变成 INSERT 的SQL 语句的存储过程(sql server)

    来源自http://vyaskn.tripod.com/code.htm#inserts SET NOCOUNT ON GO PRINT 'Using Master database' USE mas ...