Machine Schedule
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17454   Accepted: 7327

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
题意:这题的题意是说,有两台机器A,B,每个机器有m种模式,对于每一个任务i,可以在模式a[i]或者b[i]上进行,,任务可以以任意的顺序执行,每一次转换模式,机器每台机器就
要重新启动一次,求怎样安排顺序,使得机器重启的次数最少。


这张图很显然是一张二分图,求出他的最小点覆盖,就等价于用尽量少的模式在执行任务。但是这题有一点是需要注意的,刚开始两台机器都处于0模式,因此这个模式要删除掉,也就是不处理。

代码实现:

 #include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = ;
int k, n, m, first[MAXN], sign;
struct Edge
{
int to, w, next;
} edge[MAXN * ];
void init()
{
for(int i = ; i <= n; i++ )
{
first[i] = -;
}
sign = ;
}
void add_edge(int u, int v, int w)
{
edge[sign].to = v;
edge[sign].w = w;
edge[sign].next = first[u];
first[u] = sign++;
}
int link[MAXN], vis[MAXN];
bool match(int x)
{
for(int i = first[x]; ~i; i = edge[i].next)
{
int to = edge[i].to;
if(!vis[to]&&(x!=&&to!=))
{
vis[to] = ;
if(!link[to] || match(link[to]))
{
link[to] = x;
return ;
}
}
}
return ;
}
int main()
{
while(~scanf("%d",&n) && n)
{
scanf("%d %d",&m, &k);
init();
int ans = ;
for(int i = ; i <= k; i++ )
{
int u, v,z;
scanf("%d%d%d",&z, &u, &v);
add_edge(u, v, );
}
memset(link, , sizeof(link));
for(int i = ; i <= n; i++ )
{
memset(vis, , sizeof(vis));
if(match(i))
{
ans++;
}
}
printf("%d\n", ans);
} return ;
}

Machine Schedule poj1325的更多相关文章

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

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

  2. POJ-1325 Machine Schedule,和3041有着异曲同工之妙,好题!

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K       Description As we all know, machine ...

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

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

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

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

  5. Machine Schedule

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

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

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

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

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

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

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

  9. HDU 1150:Machine Schedule(二分匹配,匈牙利算法)

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

随机推荐

  1. Dubbo-Zookeeper安装

    安装zookeeper: 1.拖入tar.gz包,解压 2.建立/usr/zookeeper路径,该路径创建logs文件夹和data文件夹 3.进入conf目录,复制一份zoo_sample.cfg为 ...

  2. HTML多图无缝循环翻页效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. C语言之四舍五入

    在C语言中,如果进行强制类型转换,它会将所需要取的位数直接提取出来,而其他位数的数字会被直接删除,不会对提取出来的位数有任何影响 所以如果我们需要提高精度,对所取的数进行四舍五入,需要给所需去的数的最 ...

  4. 小小知识点(四)——MATLAB如何画等高线图和线性规划约束方程

    MATLAB程序: figure contourf(x,y,data) % 画等高线 hold on plot(x,y(x)) %画线性规划约束方程1 hold on plot(y,x(y)) %画线 ...

  5. openstack搭建之-nova配置(10)

    一. base节点设置数据库 mysql -u root -proot CREATE DATABASE nova_api; CREATE DATABASE nova; CREATE DATABASE ...

  6. kettle查询

    >流查询: 1.转换设计 2.主数据 3.查询数据 4.流查询 5.数据预览 查询中有重复数据默认获取最后一条:查询数据中有重复数据,默认获取到了最后一条数据. 主数据中无匹配数据则在结果集中返 ...

  7. SpringCloud学习笔记:负载均衡Ribbon(3)

    1. RestTemplate简介 RestTemplate是Spring Resource中一个访问第三方RESTful API接口的网络请求框架. RestTemplate是用来消费REST服务的 ...

  8. Python学习之路——三元运算符推导式

    三元运算符 # 生成器:包含yield关键字的函数就是生成器 def my_generator(): yield 1 yield 2 yield 3 g_obj = my_generator() # ...

  9. mpvue——引入vant_weapp组件

    克隆仓库 克隆后,将dist目录下的所有文件复制到项目中的/static/vant/目录下,vant目录是我自己创建为了区分的 git clone https://github.com/youzan/ ...

  10. mongoDB 数据库简介

    背景概念-数据库类型 对比关系型数据库 优点 : 逻辑清晰.容易理解,结构类似表格 使用 sql 语句技术成熟,使用方便 数据一致性好,完整性好 关系型数据库比较成熟,可以使用一些复杂操作 缺点 : ...