poj1325 machine schedule
2016-05-13 18:10
246 查看
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.
左部图是A的模式,右部图是B的模式。
对于每个任务在两个模式之间连边。
求最小覆盖即为答案。
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.
左部图是A的模式,右部图是B的模式。
对于每个任务在两个模式之间连边。
求最小覆盖即为答案。
#include<cstdio> #include<cstring> #define M(a) memset(a,0,sizeof(a)) int m,n,k,f[210],first[210],next[3000],to[3000]; bool v[210]; bool dfs(int p) { int i,j,k,x,y,z; for (i=first[p];i;i=next[i]) if (!v[to[i]]) { v[to[i]]=1; if (!f[to[i]]||dfs(f[to[i]])) { f[to[i]]=p; return 1; } } return 0; } int main() { int i,j,k,x,y,z,ans; while (scanf("%d",&n)&&n) { scanf("%d%d",&m,&k); M(f); M(first); M(next); M(to); for (i=1;i<=k;i++) { scanf("%*d%d%d",&x,&y); if (x*y==0) continue; x*=2; y=y*2+1; to[i*2]=y; next[i*2]=first[x]; first[x]=i*2; to[i*2+1]=x; next[i*2+1]=first[y]; first[y]=i*2+1; } ans=0; for (i=2;i<=n*2;i+=2) { M(v); if (dfs(i)) ans++; } printf("%d\n",ans); } }
相关文章推荐
- java的一些难点
- 浙大 PAT Advanced level 1022. Digital Library (30)
- Magento中打印SQL语句来调试
- Python
- SQL server 和Oracle 序列
- php的命名规范
- php yield
- Spring学习总结(8)——25个经典的Spring面试问答
- Servlet Error
- HDU 1013 Digital Roots【水题】
- Spring学习总结(8)——25个经典的Spring面试问答
- 学习Java有没有什么捷径
- margin属性
- spring boot 拦截器实现防重复提交
- (五)Hibernate 操作对象
- 时间对话框
- jdk linux 解压安装
- 图片压缩保存 处理三星拍照图片旋转问题的部分方法
- centos6.5配置lamp环境
- SVN使用教程2