Machine Schedule
Machine Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4122 Accepted Submission(s): 2005
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.
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
Asia 2002, Beijing (Mainland China)
Recommend
Ignatius.L
分析:事情是这样的,把机器的工作状态看成图的顶点,把每一项工作看成连接了两个顶点的边,那么问题就转化成了求二分图的最小顶点覆盖.
#include<stdio.h>
#include<string.h>
int N,M,K;
int match[];
bool visit[],G[][];
bool DFS(int k)
{
int t;
for (int i=;i<M;i++)
if (G[k][i] && !visit[i])
{
visit[i]=;
t=match[i];
match[i]=k;
if (t==- || DFS(t)) return true;
match[i]=t;
}
return false;
}
int Max_match()
{
int ans=;
memset(match,-,sizeof(match));
for (int i=;i<N;i++)
{
memset(visit,,sizeof(visit));
if (DFS(i)) ans++;
}
return ans;
}
int main()
{
while (scanf("%d",&N)!=EOF)
{
if (N==) return ;
scanf("%d%d",&M,&K);
memset(G,,sizeof(G));
for (int i=;i<=K;i++)
{
int s,u,v;
scanf("%d%d%d",&s,&u,&v);
if (u && v) G[u][v]=;
}
printf("%d\n",Max_match());
}
return ;
}
Machine Schedule的更多相关文章
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu-----(1150)Machine Schedule(最小覆盖点)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11958 Accepted: 5094 ...
- HDU 1150:Machine Schedule(二分匹配,匈牙利算法)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- Machine Schedule poj1325
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17454 Accepted: 7327 ...
随机推荐
- ruby on rails揭开route路由的真面目
文章是从我的个人主页上粘贴过来的, 大家也可以访问我的主页 www.iwangzheng.com 最近的项目里发现一个问题,大师和pp写的index页面就好使,我写index页面就不往index页面跳 ...
- php友好格式化时间
php格式化时间显示 function toTime($time) {//$time必须为时间戳 $rtime = date("Y-m-d H:i",$time); $htime ...
- qcow2文件压缩
qemu-img convert -O qcow2 /path/old.img.qcow2 /path/new.img.qcow2 转自:https://havee.me/linux/2011-09/ ...
- zpf 视图
2014年8月19日 18:12:16 smarty使用了2年, 使用PHP本身做模版引擎也有4个多月了, 最终还是在我的这个框架中抛弃了smarty,转用原生的PHP代码做模版引擎,并简单写了一个视 ...
- Java for LeetCode 060 Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- PHP--TP框架----操作数据库
//操作数据库 //$attr = $m->select(); //查询所有数据 //$attr = $m->s ...
- input框颜色修该
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JPush Wiki
极光推送包含有通知与自定义消息两种类型的推送.本文描述他们的区别,以及建议的应用场景. 功能角度 通知 或者说 Push Notification,即指在手机的通知栏(状态栏)上会显示的一条通知信息. ...
- Android之shape属性详解
有时候 ,为了满足一些需求,我们要用到 shape 去定义 一些背景,shape 的用法 跟图片一样 ,可以给View设置 Android:background="@drawable/sha ...
- linux下跳板机跟客户端之间无密码登陆
创建证书: [root@lnmp src]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which ...