POJ 1325 Machine Schedule (最大二分匹配)
2013-02-26 14:04
399 查看
Machine Schedule
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
Sample Output
Source
Beijing 2002
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9868 | Accepted: 4193 |
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
Source
Beijing 2002
#include <cstdio> #include <cstring> #include <vector> using namespace std; const int maxn=111; vector<int>edge[maxn]; bool vis[maxn]; int mach[maxn],n,m; bool find(int now) { int i,v; for(i=0; i<edge[now].size(); ++i) if(!vis[v=edge[now][i]]) { vis[v]=true; if(mach[v]==-1||find(mach[v])) { mach[v]=now; return true; } } return false; } int main() { int k,i,id,x,y; while(scanf("%d",&n)&&n) { scanf("%d%d",&m,&k); memset(mach,-1,sizeof(mach)); for(i=0; i<n; i++) edge[i].clear(); for(i=0; i<k; i++) { scanf("%d%d%d",&id,&x,&y); if(x&&y) edge[x].push_back(y); } int ans=0; for(i=1; i<n; i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",ans); } return 0; }
相关文章推荐
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
- poj 3692 Kindergarten(二分匹配,最大独立集)
- poj 1325 Machine Schedule 匈牙利二分匹配 基础
- POJ 1325 Machine Schedule (最小点覆盖 && 二分图最大匹配)
- POJ 3020 最小路径覆盖 = 顶点数-最大匹配数 二分匹配
- poj 1325 Machine Schedule(最小顶点覆盖+最大匹配)
- HLG 1392 (POJ 2112 Optimal Milking)【二分+二分图多重匹配 + 最大流】
- POJ 1325-Machine Schedule(二分图_最大匹配最小点覆盖)
- poj 1325 Machine Schedule(最小点覆盖即最大匹配,匈牙利算法)
- poj 1719最大二分匹配hungary算法
- POJ 1274 The Perfect Stall(最大二分匹配)
- POJ 1325 最大匹配
- POJ 1274 The Perfect Stall 二分匹配||最大流(简单题)
- POJ 1325 Machine Schedule(二分匹配-hungary)
- poj 2594 Treasure Exploration(最小路径覆盖/二分最大匹配)
- POJ 3041 (二分匹配->网络最大流)
- poj 3020 二分最大匹配
- POJ 3041 Asteroids 最小点覆盖==最大二分匹配