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. 求和函数 sum详解

    sum()的参数是一个list: >>> sum([1,2,3]) 6 >>> sum(range(1,3)) 3 还有一个比较有意思的用法 a = range(1 ...

  2. 欢迎使用skymvc框架,简单易用的php框架

    skymvc是一款轻量.简单易用的php mvc框架,经过多个项目实践改良. 特点: 1.mvc架构 2.m.v.c之间可以互相调用 3.简单的路由控制 R("/index.php" ...

  3. yii2源码学习笔记(十一)

    Controller控制器类,是所有控制器的基类,用于调用模型和布局. <?php /** * @link http://www.yiiframework.com/ * @copyright C ...

  4. CentOS使用sudo提示用户不在sudoers文件中的解决方法

    1切换到root用户[linux@localhost ~]$ su root密码:[root@localhost ~]# 2查看/etc/sudoers文件权限,如果只读权限,修改为可写权限 [roo ...

  5. “\n”与“\r”的区别

    ASCII中“\n”代表着换行,“\r”代表着将光标移动到当前显示行的最左边.

  6. 对SVM的个人理解

    对SVM的个人理解 之前以为SVM很强大很神秘,自己了解了之后发现原理并不难,不过,“大师的功力在于将idea使用数学定义它,使用物理描述它”,这一点在看SVM的数学部分的时候已经深刻的体会到了,最小 ...

  7. 重燃你的PHP安全分析之火

    关于脚本安全这个话题好像永远没完没了,如果你经常到国外的各种各样的bugtraq上,你会发现有一半以上都和脚本相关,诸如SQL injection,XSS,Path Disclosure,Remote ...

  8. Stanford CoreNLP--常量定义

    在运行Stanford CoreNLP过程中会用到tokenize,pos等参数,这些以常量形式定义在edu.stanford.nlp.pipeline.Annotator中,具体如下: /** * ...

  9. [ecmall]Ecmall 后台添加模板编辑区

    例如,想把品牌/index.php?app=brand页面做成可编辑的. 首先,找到后台admin\includes\menu.inc.php第61行 'template' => array( ...

  10. ANDROID_MARS学习笔记_S03_005_Geocoder、AsyncTask

    一.代码1.xml(1)AndroidManifest.xml <uses-permission android:name="android.permission.ACCESS_FIN ...