Machine Schedule

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1150

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

HINT

题意

有2个机器m个任务,每一个任务在a机器需要状态x,在b机器需要状态y,然后每个机器开始状态都是0,改变状态花费为1,然后问你最小花费完成这些任务

题解:

把每一个任务都当成一个边,把x状态和y连接起来,然后就是求最小的点来覆盖所有的边,就是一个最少点覆盖问题

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//************************************************************************************** inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int ma[maxn][maxn];
int vis[maxn];
int match[maxn];
int n,m;
vector<int> e[maxn];
int dfs(int a)
{
for(int i=;i<e[a].size();i++)
{
if(vis[e[a][i]]==)
{
vis[e[a][i]]=;
if(match[e[a][i]]==-||dfs(match[e[a][i]]))
{
match[e[a][i]]=a;
return ;
}
}
}
return ;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==)
break;
memset(match,-,sizeof(match));
for(int i=;i<n;i++)
e[i].clear();
m=read();
int k=read();
for(int i=;i<k;i++)
{
int a=read();
int x=read(),y=read();
if(x>&&y>)
{
e[x].push_back(y);
}
}
int ans=;
for(int i=;i<n;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i)==)
ans++;
}
printf("%d\n",ans);
} }

hdu 1150 Machine Schedule 最少点覆盖的更多相关文章

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

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

  2. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

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

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  4. hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...

  5. HDU——1150 Machine Schedule

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

  6. 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule

    二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...

  7. hdu 1150 Machine Schedule (二分匹配)

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

  8. hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版

    //两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...

  9. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

随机推荐

  1. [转]关于MyEclipse下的项目无法使用BASE64Encoder问题的解决办法

    [链接] http://blog.csdn.net/longlonglongchaoshen/article/details/75087616

  2. 在Mac上搭建ReactNative开发环境

    1.安装Homebrew,   Mac系统的包管理器,用于安装NodeJS和一些其他必需的工具软件. /usr/bin/ruby -e "$(curl -fsSL https://raw.g ...

  3. 安装window系统

    安装服务器系统,进入windowpe后将iso中sources,bootmgr,和boot拷贝到C盘,执行bootsect.exe  /nt60  c:,调试froad13的consle win8 改 ...

  4. TObject、TPersisent 、TComponent、TControl、TGraphicControl、TWinControl 关系图

    VCL的类图结构               TObject                 |               TPersisent                 |         ...

  5. Java 中判断字符串是否为空

    public class TestString { public static void main(String[] args) { String abc = null; //先判断是否为null再判 ...

  6. 利用sys.dm_db_index_physical_stats查看索引大小/碎片等信息

    我们都知道,提高sql server的数据查询速度,最有效的方法,就是为表创建索引,而我们对数据表进行新增,删除,修改的时候,会产生索引碎片,索引碎片多了,对性能产生很大的影响,索引碎片越多对数据库查 ...

  7. vector 测试

    vector 测试 */--> div.org-src-container { font-size: 85%; font-family: monospace; } pre.src { backg ...

  8. who am i ?

    Id:Ox9A82 Email:hucvbty@gmail.com 微博:http://weibo.com/1828621423 知乎:Ox9A82 常乐村男子职业技术学院 Syclover拖后腿成员 ...

  9. I​n​n​o​ ​s​e​t​u​p​ ​常​用​修​改​技​巧

    Inno setup 常用修改技巧1 .如何让协议许可页面默认选中我同意按钮 [code]procedure InitializeWizard();beginWizardForm.LICENSEACC ...

  10. Spring整合junit测试

    本节内容: Spring整合junit测试的意义 Spring整合junit测试 一.Spring与整合junit测试的意义 在没整合junit之前,我们在写测试方法时,需要在每个方法中手动创建容器, ...