杭电1150 Machine Schedule
来源:互联网 发布:深海鱼油 知乎 编辑:程序博客网 时间:2024/05/19 02:39
由公式二分图的最小顶点覆盖数 = 二分图的最大匹配数知道,要求出把所有的任务完成,但要重启的次数最少,就是求最小顶点覆盖数,另外题目中规定如果是0模式时不用重新启动!!
Problem 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.
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.
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 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>
using namespace std;
bool map[122][122],visit[122];
int match[122];
int m,n;
bool dfs(int k)
{
int i;
for(i=0;i<n;i++)
{
if(map[k][i] && !visit[i])
{
visit[i]=true;
if(match[i]==-1 || dfs(match[i]))
{
match[i]=k;
return true;
}
}
}
return false;
}
int main()
{
int k,a,b,c;
int s,i;
while(scanf("%d",&m)) //m,n模式。k任务数
{
if(m==0)
break;
scanf("%d%d",&n,&k);
s=0;
memset(map,false,sizeof(map));
memset(match,-1,sizeof(match));
for(i=0;i<k;i++)
{
scanf("%d%d%d",&c,&a,&b);
if(a &&b) //0模式时不用重新启动
map[a][b]=true;
}
for(i=0;i<m;i++)
{
memset(visit,false,sizeof(visit));
if(dfs(i))
s++;
}
printf("%d\n",s);
}
return 0;
}
- 杭电1150 Machine Schedule
- 杭电1150 Machine Schedule(匈牙利算法模板)
- 杭电 hdu 1150 Machine Schedule (二分匹配)
- 杭电 HDU ACM 1150 Machine Schedule(二分匹配)
- 杭电 hdu 1150 Machine Schedule (二分图最小覆盖)
- (杭电1150)(poj1325) Machine Schedule (二分图最大匹配)
- HDOJ 1150 Machine Schedule
- hdoj 1150 Machine Schedule
- hdu 1150 Machine Schedule
- hdu 1150 Machine Schedule
- hdu 1150 Machine Schedule
- HDU 1150 Machine Schedule
- hdu 1150 Machine Schedule
- HDOJ 1150 Machine Schedule
- HDU-1150-Machine Schedule
- hdu 1150 Machine Schedule
- hdu 1150 Machine Schedule
- HDU 1150 Machine Schedule
- 设计模式笔记——Singleton
- RobotFramework用户说明书翻译稿第2.1节
- 导图 SQL Server之数据转换
- Environment API 翻译
- ios常见数据类型大小
- 杭电1150 Machine Schedule
- 如何为WordPress 分割大的XML文件【灵活小窍门】
- 向Exchange Server 2010数据库可用性组DAG中添加成员失败
- 杭电1020
- Server.Execute,Server.Transfer,Response.Redirect
- Jmeter测试工具学习
- 使用最新版本Dojo1.7的dojox/mobile开发移动设备web应用
- 导图 SQL Server之安全
- self,@property用法总结