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. git完全cli指南之详细思维导图整理分享

    一直以来都觉得 在开发过程中 能用命令行的还是用命令行 能用快捷键的就要快捷键 前期可能要点学习成本 但是熟练后带来的好处还是非常可观的 所以一直坚持使用命令行的方式来使用git 基本上每个操作都能心 ...

  2. RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your c

    Error Msg: Traceback (most recent call last): File "<string>", line 1, in <module ...

  3. 【学习总结】GirlsInAI ML-diary 总

    2019-1-7 GirlsInAI第一期: 人工智障工程师养成计划,代号ML-diary 原博github链接:Girls-In-AI 环境:Windows / MacOS 工具:Anaconda ...

  4. delete *p可以替代delete[] p吗?

    在stackoverflow看到一个标题描述的问题,问题链接是:https://stackoverflow.com/questions/55524140/is-delete-p-an-alternat ...

  5. Python——pickle模块(永久存储)

    一.作用 讲字典.列表.字符串等对象进行持久化,存储到磁盘上,方便以后使用. 二.dump()方法 pickle.dump(对象,文件,[使用协议]) 作用:将要持久化的数据“对象”,保存到“文件中” ...

  6. EasyTouch5ForSiki学院

    总结: 这里面的一些功能,就可以拿来做移动或者PC的很多功能了,这是一个很有用的插件. 禁用0618错误 EasyTouch4_x的写法: using HedgehogTeam.EasyTouch; ...

  7. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2)

    A. Be Positive 题意:给出一个数组 每个树去除以d(d!=0)使得数组中大于0的数 大于ceil(n/2) 求任意d 思路:数据小 直接暴力就完事了 #include<bits/s ...

  8. 【XSY3147】子集计数 DFT 组合数学

    题目大意 给定一个集合 \(\{1,2,\ldots,n\}\),要求你从中选出 \(m\) 个数,且这 \(m\) 个数的和是 \(k\).问方案数 \(\bmod 998244353\) \(0\ ...

  9. Linux内核参数

    vm.overcommit_memory 0 - 表示内核将检查是否有足够的可用内存供应用进程使用:如果有足够的可用内存,内存申请允许:否则,内存申请失败,并把错误返回给应用进程. 1 - 表示内核允 ...

  10. WC2019滚粗记

    什么?你问WC2019滚粗记在哪里? 抱歉,这篇文章鸽了. 原因? 引用神仙\(yyb\)的话. 恩,想了想还是更一点吧. Day 0 签到海星,我写了个大大的\(Cgod\)有没有人看见啊,然后被广 ...