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. MFC坐标空间与映射模式

    逻辑坐标:使用GDI绘图时使用的坐标系 设备坐标系:实际设备(显示器.打印机)的坐标系,即我们实际看到的坐标系. 坐标空间 在Windows NT/2000中Win32 API中支持以下四层坐标空间: ...

  2. MySQL 5.7 深度解析: 半同步复制技术

    复制架构衍生史 在谈这个特性之前,我们先来看看MySQL的复制架构衍生史. MySQL的复制分为四种: 普通的replication,异步同步. 搭建简单,使用非常广泛,从mysql诞生之初,就产生了 ...

  3. hdu 2896 字典树解法

    #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...

  4. LoadRunner参数化详解(转)

    距离上次使用loadrunner 已经有一年多的时间了.初做测试时在项目中用过,后面项目中用不到,自己把重点放在了工具之外的东西上,认为性能测试不仅仅是会用工具,最近又想有一把好的利器毕竟可以帮助自己 ...

  5. Ajax请求SpringMVC

    @RequestMapping(value = "/loadMenu", method = RequestMethod.GET) @ResponseBody public Arra ...

  6. C#WebClient常见用法

    System.Net.WebClient.DownloadFile(Uri address, String fileName) namespace:System.Net 参数: address:The ...

  7. 初识ASP.NET CORE:一、HTTP pipeline

    完整的http请求在asp.net framework中的处理流程: Asp.Net HttpRequest--> HTTP.exe--> inetinfo.exe(w3wp.exe)-& ...

  8. 父窗口的treeview在调用其他窗体的ShowDialog后闪烁问题

    ShowDialog(this)改为ShowDialog()即可! 具体原理未深究

  9. flash builder关掉自动编译功能

    菜单栏 项目,里面有个自动构建,把√去掉就ok了

  10. LoadRunner录制不弹出IE浏览器,event=0

    系统环境:win7,安装了IE.360.firefox.搜狗高速浏览器: 起初刚装完loadrunner11的时候,选了IE进行录制,就是不能打开IE,算了,那就用loadrunner默认的设置,居然 ...