Machine Schedule
来源:互联网 发布:java中的观察者模式 编辑:程序博客网 时间:2024/05/20 13:39
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
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
思路:
就是二分图最多有几条边的问题。
AC代码:
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>using namespace std;#define T 101int n,m,k;int g[T][T],mk[T],x[T],y[T];int path(int u){int v;for(v=1;v<=m;++v){if(g[u][v]&&!mk[v]){mk[v]=1;if(y[v]==-1||path(y[v])){x[u]=v;y[v]=u;return 1;}}}return 0;}void MaxMatch(){int ans=0;memset(y,-1,sizeof(y));for(int i=1;i<=n;++i){memset(mk,0,sizeof(mk));if(path(i))ans++;}printf("%d\n",ans);}int main(){/*freopen("input.txt","r",stdin);*/while(~scanf("%d",&n),n){scanf("%d%d",&m,&k);memset(g,0,sizeof(g));int a,b,c;while(k--){scanf("%d%d%d",&a,&b,&c);g[b][c]=1;}memset(x,0,sizeof(x));MaxMatch();}return 0;}
- Machine Schedule
- Machine Schedule
- Machine Schedule
- Machine Schedule
- Machine Schedule
- Machine Schedule
- Machine Schedule
- pku1325 Machine Schedule
- PKU 1325 Machine Schedule
- 1325 Machine Schedule //MaxMatch
- POJ 1325 Machine Schedule
- HDOJ 1150 Machine Schedule
- POJ 1325 Machine Schedule
- Machine Schedule (P1325)
- POJ 1325 Machine Schedule
- poj 1325 Machine Schedule
- hdoj 1150 Machine Schedule
- Poj 1325 Machine Schedule
- Android 5.0的调度作业JobScheduler
- JS获取当前手机浏览器可视区域大小
- 关于hibernate纯sql查询返回结果集的问题(hbm.xml中不写多表关联)
- 拍照/摄像
- Spring Security : limit login attempts example
- Machine Schedule
- iOS编程——OC viewController 传值常用方法Delegate和Block的使用
- 黑马程序员_IO流之字符流
- Tapestry入门
- Hierarchical Clustering(学习Free Mind知识整理)和Hungarian Algorithm
- 第一次使用提示工具utils
- [LeetCode 208] Implement Trie (Prefix Tree)
- 网络爬虫:采用“负载均衡”策略来优化网络爬虫
- fedora安装busybox过程及出错处理