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. iview 无法缓存的问题

  2. 通过注解配置Bean

    之前说的三种配置方式,都是使用XML配置,现在我们说说使用注解配置Bean. 这部分内容主要分为两个部分:使用注解配置Bean,使用注解配置Bean属性. 在classpath中扫描组件 组件扫描:S ...

  3. idea 配置 jdk tomcat

    https://blog.csdn.net/cxjsnail/article/details/80018519 1.  安装IntelliJ IDEA IDEA 对maven有完美的支持,有强大的语法 ...

  4. 洛谷 p1090 合并果子

    https://www.luogu.org/problemnew/show/P1090 优先队列的经典题目 体现了stl的优越性 #include<bits/stdc++.h> using ...

  5. Lodop的TABLE中format格式化的使用

    LODOP中的ADD_PRINT_TABLE支持很多函数和计算方法,可以用tdata对table表格里额数据进行计算,用format对结果进行格式化.这个format只能和tdata搭配使用,不能单独 ...

  6. [模板] 快速傅里叶变换/FFT/NTT

    简介 FFT是多项式乘法的一种快速算法, 时间复杂度 \(O(n \log n)\). FFT可以用于求解形如\(C_i = \sum_{j=0}^i A_jB_{i-j}\)的式子. 如果下标有偏差 ...

  7. vue 拖拽移动(类似于iPhone虚拟home )

    vue 移动端 PC 兼容 元素 拖拽移动  效果演示 事件知识点 移动端 PC端 注释 touchstart mousedown 鼠标/手指按下事件 touchmove mousemove 鼠标/手 ...

  8. Hdoj 1517.A Multiplication Game 题解

    Problem Description Stan and Ollie play the game of multiplication by multiplying an integer p by on ...

  9. 多版本python及多版本pip使用

    最近做一些网站的发布程序,要用到python3,所以又安装了python3.   www.qlrx.netwww.393662.comwww.qnpx.netwww.393225.com       ...

  10. [SDOI2011]消耗战(虚树)

    洛古题面 题意:给定一棵树,割断每一条边都有代价,每次询问会给定一些点,求用最少的代价使所有给定点都和1号节点不连通 暴力\(DP\) 我们先考虑暴力怎么做 设\(dp[u]\)为以\(u\)为根的子 ...