Time Limit: 1000 MS Memory Limit: 10000 KB

64-bit integer IO format: %I64d , %I64u   Java class name: Main

[Submit] [Status] [Discuss]

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  ///n,m,k两台机器人  机器人A可完成n项工作  机器人B可完成m项工作  有K项工作
0 1 1 i,x,y 工作i可由x,y完成 以下同理
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的n个节点 B的m个节点 分别看成图的两个集合的顶点   如果可以在A和B上完成 则A B之间连边  则构成了二分图
本题求最小点覆盖集的问题 即最少的顶点覆盖全部的边(这样开关机器的次数就最少 因为为每一个点看成了机器) 转换成了求二分图的最大匹配问题 二分图的点覆盖数==匹配数
#include <iostream>
#include <string.h>
#include <stdio.h> using namespace std;
#define maxn 105 int nx,ny,jobnum; ///机器A 机器B 工作数
int g[maxn][maxn]; ///所构造的二分图
int ans; ///最大匹配数
int sx[maxn],sy[maxn]; ///path函数中DFS中用来标明顶点访问状态的数组
int cx[maxn],cy[maxn]; ///匹配情况cx[i] x集合中顶点i匹配y集合顶点cx[i]~~ int path(int u)
{
sx[u]=; ///标记访问过
int v; ///变量
for(v=; v<=ny; v++) ///一次访问y集合中的顶点
///以B集合为遍历条件 使其与集合A相对应
{
if((g[u][v]>)&&(!sy[v])) ///有连接&&v未访问过
{
sy[v]=; ///标记 if(path(cy[v])||(!cy[v])) ///v已经匹配了 但可以在v找到可增广路
{
///回退过程中修改可增广路的值 使匹配数加1
cx[u]=v; ///v匹配给u,u匹配给iv
cy[v]=u;
return ;
}
}
}
return ;
} int solve()
{
ans=;
int i;
memset(cx,,sizeof(cx)); ///
memset(cy,,sizeof(cy));
for(i=; i<=nx; i++)
///以A集合为标准 进行遍历
{
if(!cx[i])
{
memset(sx,,sizeof(sx));
memset(sy,,sizeof(sy));
ans+=path(i); ///可增广路扩充的
}
}
} int main()
{
int m,i,j; ///i j 对应m工作
while(scanf("%d",&nx)) ///A队nx人 B队ny人 jobnum份工作
{ if(nx==)
break;
scanf("%d%d",&ny,&jobnum);
memset(g,,sizeof(g)); ///初始没有边相连
for(int k=; k<jobnum; k++)
{
scanf("%d%d%d",&m,&i,&j);
g[i][j]=; ///构二分图 等于1表示i j相连
}
solve();
printf("%d\n",ans);
}
return ;
}

poj 1325 Machine Schedule的更多相关文章

  1. POJ 1325 Machine Schedule——S.B.S.

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13731   Accepted: 5873 ...

  2. poj 1325 Machine Schedule 二分匹配,可以用最大流来做

    题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...

  3. poj 1325 Machine Schedule 题解

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14479   Accepted: 6172 ...

  4. HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)

    Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...

  5. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  6. POJ 1325 Machine Schedule(最小点覆盖)

    http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ...

  7. poj 1325 Machine Schedule 解题报告

    题目链接:http://poj.org/problem?id=1325 题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1.每一个作业能运行在 A 的 ...

  8. POJ 1325 Machine Schedule(zoj 1364) 最小覆盖数

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=364 http://poj.org/problem?id=1325 题目大意: ...

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

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

随机推荐

  1. U盘分区之后如何恢复

    操作步骤: 1.插入U盘. 2.按windows键,右键点击“运行”,再左键点击以管理员身份运行. 3.输入diskpart,按enter. 4.输入list disk,按enter. 5.之后会看到 ...

  2. iMac 重装系统

    iMac重装系统相当简单.开机的时候按下option键选择恢复系统或者在开机前按下 command+R然后按开机键松开同样会进入系统选择界面: 当中有 4 个选项:Restore From Time ...

  3. JavaScript入门

    本篇内容是学习慕课网相关课程后,总结出可能未来会忘记的内容 (一)JavaScript入门操作 1.js代码插入位置,以及执行顺序 <head> <script type=" ...

  4. List集合转换为数组形式

    通过List集合对象的转类型函数 .ToArray() 如List<decimal> → deciaml[] 代码如下: var ComIdList = ComList.Select(p ...

  5. hive中的桶

    hive中有桶的概念,对于每一个表或者分区,可以进一步组织成桶,说白点,就是更细粒度的数据范围.hive采用列值哈希,然后除以桶的个数以求余的方式决定该条记录存放在哪个桶当中.使用桶的好处:1.获得更 ...

  6. VC++ excel 2 operations

    LPDISPATCH lpDisp;   //lpdispatch,接口指针 // 设置为FALSE时,加上app.Quit(); // 否则EXCEL.EXE进程会一直存在,并且每操作一次就会多开一 ...

  7. Linux内核模块简介

    一. 摘要 这篇文章主要介绍了Linux内核模块的相关概念,以及简单的模块开发过程.主要从模块开发中的常用指令.内核模块程序的结构.模块使用计数以及模块的编译等角度对内核模块进行介绍.在Linux系统 ...

  8. JQuery Object vs. DOM element

    JQuery Object 和 DOM的区别 HTML DOM 定义了访问和操作HTML文档的标准方法.其中 document 是DOM 树的根对象 ,在浏览器宿主环境中,可以通过JS操作HTML D ...

  9. Python_sklearn机器学习库学习笔记(三)logistic regression(逻辑回归)

    # 逻辑回归 ## 逻辑回归处理二元分类 %matplotlib inline import matplotlib.pyplot as plt #显示中文 from matplotlib.font_m ...

  10. html5 -js判断undefined类型

    js判断undefined类型 今天使用showModalDialog打开页面,返回值时.当打开的页面点击关闭按钮或直接点浏览器上的关闭则返回值是undefined所以自作聪明判断 var reVal ...