其实也是个最小覆盖问题

关于最小覆盖http://blog.csdn.net/u014665013/article/details/49870029

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
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
int n,m;
int map[105][105];
bool visited[105];
int match[105]; bool find(int i) ///查找当前的i是否可以匹配
{
int j;
for(j=1;j<=m;j++)
{
if(map[i][j]&&!visited[j])
{
visited[j]=1;
if(match[j]==-1||find(match[j]))
{
match[j]=i;
return 1;
}
}
}
return 0;
}
int main()
{
int k,i,x,y,ans;
while(~scanf("%d",&n)&&n)
{
ans=0;
scanf("%d%d",&m,&k);
memset(map,0,sizeof(map));
memset(match,-1,sizeof(match)); for(i=0;i<k;i++)//对有意思的进行初始化
{
scanf("%d%d%d",&x,&x,&y);
map[x][y]=1;
}
for(i=1;i<=n;i++)
{
memset(visited,0,sizeof(visited));//开始标记为全部没有访问
if(find(i)) ans++;
}
printf("%d\n",ans);
}
return 0;
}

Machine Schedule(最小覆盖)的更多相关文章

  1. hdu 1150 Machine Schedule 最小覆盖点集

    题意:x,y两台机器各在一边,分别有模式x0 x1 x2 ... xn, y0 y1 y2 ... ym, 现在对给定K个任务,每个任务可以用xi模式或者yj模式完成,同时变换一次模式需要重新启动一次 ...

  2. HDU 1150 Machine Schedule (最小覆盖,匈牙利算法)

    题意: 有两台不同机器A和B,他们分别拥有各种运行模式1~n和1~m.现有一些job,需要在某模式下才能完成,job1在A和B上需要的工作模式又可能会不一样.两台机器一开始处于0模式,可以切换模式,但 ...

  3. hdu-----(1150)Machine Schedule(最小覆盖点)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. POJ 1325 Machine Schedule——S.B.S.

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13731   Accepted: 5873 ...

  5. POJ1325 Machine Schedule 【二分图最小顶点覆盖】

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11958   Accepted: 5094 ...

  6. UVA1194 Machine Schedule

    题目地址:UVA1194 Machine Schedule 二分图最小覆盖模型的要素 每条边有两个端点,二者至少选择一个.简称 \(2\) 要素. \(2\) 要素在本题中的体现 每个任务要么在 \( ...

  7. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  8. Machine Schedule

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. poj 1325 Machine Schedule 二分匹配,可以用最大流来做

    题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...

  10. hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. openstack(liberty): devstack之stack.sh分析

    学习openstack,从devstack入手,是个不错的选择.devstack中,首先需要分析stack.sh都做了些什么! 这里面涉及到了很多shell的基础知识.我就做个简单的梳理,方便后续查阅 ...

  2. 面向对象设计模式--策略模式Strategy

    策略模式的UML类图(VS2013 C++版本): 策略模式的重点:每个策略对象封装一个算法,有多少个算法就有多少个对象.策略模式的意图是封装算法.要从“抽象不仅面对状态(字段.属性)还面对行为(算法 ...

  3. 一个问题提交的实例(js原生动画,原生ajax,js引用加参数)

    document.writeln("<div id=\"tanchuangwai\" class=\"tanchuangwai\" style= ...

  4. bzoj2289: 【POJ Challenge】圆,圆,圆

    Description 1tthinking随便地画了一些圆. ftiasch认为这些圆有交集(面积非零)的可能性不大.因为他实在画了太多圆,所以你被请来判断是否存在交集. Input 第1行,一个整 ...

  5. Nginx负载均衡和反向代理设置

    Nginx负载均衡: 格式: upstream 别名 {    #别名一般要有意义,能看出是做什么的 server ip:端口;    #要实现负载的服务器的ip.端口号}  例: upstream ...

  6. python asyncio笔记

    1.什么是coroutine coroutine,最早我是在lua里面看到的,coroutine最大的好处是可以保存堆栈,让程序得以继续执行,在python里面,一般是利用yield来实现,具体可以看 ...

  7. System.ArgumentOutOfRangeException: 年、月和日参数描述无法表示的 DateTime。

    c#日期控件 格式设为 yyyy-MM,通过updown 方式调整日期. 当为月度最后一天,且要调整月没有当前月的最后一天时,就会报标题错误. 如:当前为1月31日,要调整为2月时,就会报错.因为2月 ...

  8. svn merge 回滚

    聊一聊 svn merge 命令. svn 是啥就不用介绍了吧,谁用谁知道.有了 svn,开发者只要把代码提交上去,无论山崩地裂.电脑进水.硬盘格式化,哪怕换了一台电脑,都能随时把代码找回来.不过从自 ...

  9. Eclipse中Maven+Spring3.2.8+SpringMVC HelloWorld项目

    本文适合有一定spring和springmvc基础,并想使用Maven管理项目的人. 源码打包:http://pan.baidu.com/s/1hqurUcs 转载请声明出处(http://www.c ...

  10. PLSQL_解析过程及硬解析和软解析的区别(案例)

    2014-08-11 Created By BaoXinjian