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. TCP/IP 之大明王朝邮差

    本系列文章全部摘选自"码农翻身"公众号,仅供个人学习和分享之用.文章会给出原文的链接地址,希望不会涉及到版权问题. 个人感言:真正的知识是深入浅出的,码农翻身" 公共号将 ...

  2. zedboard如何从PL端控制DDR读写(五)

    有了前面的一堆铺垫.现在终于开始正式准备读写DDR了,开发环境:VIVADO2014.2 + SDK. 一.首先要想在PL端通过AXI去控制DDR,我们必须要有一个AXI master,由于是测试,就 ...

  3. 用odbc连接oracle问题

    如果用11g的客户端,然后通过odbc(远程连接)连接10g的oracle,会出现监听程序无法启动(ORA-12541: TNS: 无监听程序) 此时需要在客户端目录中D:\instantclient ...

  4. git 放弃本地修改 强制更新

    git reset --hard origin/master

  5. dll 导出函数名的那些事

    dll 导出函数名的那些事 关键字: VC++  DLL  导出函数 经常使用VC6的Dependency或者是Depends工具查看DLL导出函数的名字,会发现有DLL导出函数的名字有时大不相同,导 ...

  6. [简单]docx4j常用方法小结

    http://53873039oycg.iteye.com/blog/2194479?utm_source=tuicool&utm_medium=referral —————————————— ...

  7. MFCC matlab code

    %function ccc=mfcc(x) %归一化mel滤波器组系数 filename=input('input filename:','s'); [x,fs,bits]=wavread(filen ...

  8. php文章内容分页并生成相应的htm静态页面代码

    代码如下: <?php $url='test.php?1=1'; $contents="fjka;fjsa;#page#批量生成分成文件并且加上分页代码"; $ptext = ...

  9. JS常见问题

    语法错误 由于编程语言中的语法比自然语言的语法要严格得多,因此在编写脚本时对细节应倍加关注.例如,如果您本意是将字符串作为某个参数,但是在键入时忘了使用引号引起来,就会产生问题. 脚本解释顺序 对 J ...

  10. left join ,right join ,inner join ,cross join 区别

    left join ,right join ,inner join ,cross join 区别(参考:http://zhidao.baidu.com/link?url=gpOl9HXZR0OrQuy ...