Machine Schedule
来源:互联网 发布:腾讯程序员待遇 编辑:程序博客网 时间:2024/06/06 19:37
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 will be terminated by a line containing a single zero.
Output
Sample Input
5 5 100 1 11 1 22 1 33 1 44 2 15 2 26 2 37 2 48 3 39 4 30
Sample Output
3
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[1005][1005],vis[102],cn[102];int n,m;int fun(int u){ int i; for(i=1;i<m;i++) { if(a[u][i]&&!vis[i]) { vis[i]=1; if(cn[i]==-1||fun(cn[i])) { cn[i]=u; return 1; } } } return 0; }int hun(){ int i,count=0; memset(cn,-1,sizeof(cn)); for(i=1;i<n;i++) { memset(vis,0,sizeof(vis)); if(fun(i)) count++; } return count;}int main(){ int k,i,x,y; while(scanf("%d",&n)!=EOF&&n) { scanf("%d%d",&m,&k);//m为顶点 memset(a,0,sizeof(a)); for(i=0;i<k;i++) { scanf("%d%d%d",&x,&x,&y); if(x&&y) a[x][y]=1; } printf("%d\n",hun()); }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
- J2EE入门
- 操作系统学习笔记:进程同步
- 【转载】杭电acm分类
- StrutsPrepareAndExecuteFilter
- POJ 3678 - Katu Puzzle(2-SAT)
- Machine Schedule
- VC 读写Excel (第三方类CSpreadSheet)
- 自定义ProgressBar的样式
- 机器学习注意
- 多线程下的单例模式
- BFS算法实现
- Qt、opencv程序在别人电脑上运行
- 第二章第九题
- Pop Sequence