hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150
Machine Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6733 Accepted Submission(s):
3375
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.
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.
the minimal times of restarting machine.
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int Map[][],vis[],n,m;
int ok[]; bool Find(int x)
{
for (int i=;i<=m;i++)
{
if (Map[x][i]==&&!vis[i])
{
vis[i]=;
if (ok[i]==-)
{
ok[i]=x;
return true;
}
else
{
if (Find(ok[i])==true)
{
ok[i]=x;
return true;
}
}
}
}
return false;
} int main()
{
int k,i,x,y;
int ans;
while (~scanf("%d",&n))
{
ans=;
memset(Map,,sizeof(Map));
memset(ok,-,sizeof(ok));
if (n==)
break;
scanf("%d%d",&m,&k);
while (k--)
{
scanf("%d%d%d",&i,&x,&y);
//if(x>0&&y>0)
Map[x][y]=;
}
for (int j=;j<=n;j++)
{
memset(vis,,sizeof(vis));
if (Find(j)==true)
ans++;
}
printf ("%d\n",ans);
}
return ;
}
hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)的更多相关文章
- hdu 1150 Machine Schedule (二分匹配)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule
二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- HDU - 1150 Machine Schedule(最小点覆盖数)
1.有两台机器A和B以及N个需要运行的任务.A机器有n种不同的模式,B机器有m种不同的模式,而每个任务都恰好在一台机器上运行.如果它在机器A上运行,则机器A需要设置为模式xi,如果它在机器B上运行,则 ...
- HDU 1150:Machine Schedule(二分匹配,匈牙利算法)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1150 Machine Schedule (最小覆盖,匈牙利算法)
题意: 有两台不同机器A和B,他们分别拥有各种运行模式1~n和1~m.现有一些job,需要在某模式下才能完成,job1在A和B上需要的工作模式又可能会不一样.两台机器一开始处于0模式,可以切换模式,但 ...
- hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
随机推荐
- PokeCats开发者日志(十一)
现在是PokeCats游戏开发的第六十天的上午,易版权的状态变为了待收证,但愿不久就能送到了吧.
- C#中Console.ReadLine()和Console.Read()有何区别?
Console.Read 表示从控制台读取字符串,不换行. Console.ReadLine 表示从控制台读取字符串后进行换行. Console.Read() Console.ReadLine()方法 ...
- java 基础--继承--007
1,子类只能继承父类所有非私有成员 2,子类不能继承父类的构造方法,但可以通过super去访问父类构造方法 3,子类成员变量和父类成员变量名称不一样,如果一样类似于重写,按子类处理,如果一样,就近原则 ...
- MyBatis原理系列
原理分析之一:从JDBC到Mybatis 原理分析之二:框架整体设计 原理分析之三:初始化(配置文件读取和解析) 原理分析之四:一次SQL查询的源码分析
- table中的td限制宽度width也不能让字符过长变成省略号生效?
table中的td限制宽度width也不能让字符过长变成省略号生效? http://blog.csdn.net/java_mr_zheng/article/details/49423247 CSS t ...
- Socket网络编程实例1
Socket: 对所有上层协议(TCP/IP,UDP等)的底层封装. 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. 建立网络通信连接至少要一对端口号(so ...
- hadoop 使用Avro求最大值
在上例中:hadoop MapReduce辅助排序解析,为了求每年的最大数据使用了mapreduce辅助排序的方法. 本例中介绍利用Avro这个序列化框架的mapreduce功能来实现求取最大值.Av ...
- [CF551E]GukiZ and GukiZiana
题目大意:一个长度为$n(n\leqslant5\times10^5)$的数组,有两个操作: $1\;l\;r\;x:$把区间$[l,r]$加上$x$ $2\;x:$询问$x$第一次出现和最后一次出现 ...
- ubuntu简易教程(如何使用noi linux)
目录 linux环境下的基础操作 命令行操作 编辑器 程序编译 程序调试 gdb的使用 对拍 在提高组的考试中要求使用noi linux,因此了解一下如何在linux环境下编程是很有必要的. linu ...
- 【BZOJ4520】K远点对(KD-Tree)
[BZOJ4520]K远点对(KD-Tree) 题面 BZOJ 洛谷 题解 考虑暴力. 维护一个大小为\(K\)的小根堆,然后每次把两个点之间的距离插进去,然后弹出堆顶 这样子可以用\(KD-Tree ...