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. iOS软件开发架构理解

    这个东西是硬伤,框架?自带的mvc? 自带的UIViewController UIView UINavigationController 这些算不算?当然算的,cocoa框架嘛,大家都知道. 其实,我 ...

  2. java三大框架之一hibernate使用入门

    综述:Hibernate的作用就是让实体类与数据库映射,使数据持久化,用于替代JDBC,使我们不致于写那么多sql语句代码. 1. 首先在官网www.hibernate.org下载hibernate包 ...

  3. 在一般处理文件中访问Session需要添加IRequiresSessionState(转载)

    原文:http://blog.csdn.net/cdsnaspnet/article/details/5695625s 通常我们经常,通过session判定用户是否登录.还有一些临时的.重要的数据也尝 ...

  4. mysql错误用法insert into where

    mysql中给表中插入数据,一般使用insert into. 但是在插入数据时,有时会根据条件来插入数据,比如insert into t_person(num,name) values(1,'lily ...

  5. 8.11 CSS知识点4

    边框样式 1.边框宽度 border-width:medium | thin | thick | length border-top-width  设置上边框宽度 border-bottom-widt ...

  6. Add Binary <leetcode>

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

  7. [原创] Legato 8.1 oracle full backup skip 奇怪的问题处理过程 -- 非调度日期手工运行调度也不成功(skip)

    转载请注明出处: http://www.cnblogs.com/fengaix6/p/4677024.html 作者:飄ぺ風 环境: a. Server: Legato 8.1.2, aix 6.1 ...

  8. TortoiseSVN汉化包装了,不管用,仍然是英文菜单

    TortoiseSVN装了后,把对应的汉化包也装了,但不管用,仍然是英文菜单. 想着是因为没有重启的原因,但是重启了再装,仍然看不到中文工菜单. 想了一下,TortoiseSVN汉化包在装的时候,没有 ...

  9. c#开发Mongo笔记第四篇

    今天是个伟大的日子,不得不说小苹果的歌词真是深入人心啊. 不过今天伟大并不是因为我种下一颗种子,而是我从今天不再写demo,而是进入项目的正式开发当中,毕竟项目时间有限(想必各位码农也都深有体会吧), ...

  10. c# 集合适配器

    using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...