hdu-----(1150)Machine Schedule(最小覆盖点)
Machine Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5817 Accepted Submission(s): 2932
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 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.
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
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
int const maxn=;
int n,m,k;
bool mat[maxn][maxn];
bool vis[maxn];
int mac[maxn];
bool match(int x)
{
for(int i=;i<=m;i++)
{
if(mat[x][i]&&!vis[i]){
vis[i]=;
if(!mac[i]||match(mac[i])){
mac[i]=x;
return ;
}
}
}
return ;
}
int main(){
int a,b,c;
//freopen("test.in","r",stdin);
while(scanf("%d",&n),n!=){
memset(mat,,sizeof(mat));
memset(mac,,sizeof(mac));
scanf("%d%d",&m,&k);
for(int i=;i<k;i++){
scanf("%d%d%d",&a,&b,&c);
mat[b][c]=;
}
int ans=;
for(int i=;i<=n;i++){
memset(vis,,sizeof(vis));
if(match(i))ans++;
}
printf("%d\n",ans);
}
return ;
}
hdu-----(1150)Machine Schedule(最小覆盖点)的更多相关文章
- hdu 1150 Machine Schedule 最小覆盖点集
题意:x,y两台机器各在一边,分别有模式x0 x1 x2 ... xn, y0 y1 y2 ... ym, 现在对给定K个任务,每个任务可以用xi模式或者yj模式完成,同时变换一次模式需要重新启动一次 ...
- HDU 1150 Machine Schedule (最小覆盖,匈牙利算法)
题意: 有两台不同机器A和B,他们分别拥有各种运行模式1~n和1~m.现有一些job,需要在某模式下才能完成,job1在A和B上需要的工作模式又可能会不一样.两台机器一开始处于0模式,可以切换模式,但 ...
- 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule 最少点覆盖
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
- hdu 1150 Machine Schedule (二分匹配)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU——1150 Machine Schedule
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- C#四则运算之策略模式
Calculator.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- Mybatis+struts2+spring整合
把student项目改造成ssm struts2 +mybatis+spring 1,先添加spring支持:类库三个,applicationContext.xml写在webinf下四个命名空间,监 ...
- JAVA中在Myeclipse里把表导入成相应的poco实体类
参考:地址: http://blog.csdn.net/jintaiyong/article/details/7383982
- Eclipse使用Jetty(转)
eclipse 与 jetty 结合的最佳实践 http://www.cnblogs.com/mignet/archive/2011/12/04/eclipse_jetty_perfect_integ ...
- Doragon Kuesuto 1.15
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { ; ; ; int actio ...
- GCC编译器和GDB调试器常用选项
http://blog.csdn.net/u014328976/article/details/46745349 GCC编译器 gcc hello.c -o hello ...
- lmdb存储的一些库相关函数
MDB_env 为一个结构体,Opaque structure for a database environment. MDB_txn :Opaque structure for a transact ...
- STM32学习笔记(一) 如何新建一个STM32工程模板
学习stm32,第一步就是选择开发工具了,GCC,MDK,IAR每一种都有自己的优劣势,这里我选择使用MDK软件实现STM32模板.当然如果想更快的接触stm32实例,领略嵌入式开发的魅力,STM也提 ...
- android设置软键盘搜索键以及监听搜索键点击时发生两次事件的问题解决
在输入框中加入android:imeOptions="actionSearch",调用软键盘时,回车键就会显示搜索二字. 我想在点击搜索时,跳转到下一个页面,但是调用setOnKe ...
- 在Spring Data JPA 中使用Update Query更新实体类
对于 Spring Data JPA 使用的时间不长,只有两年时间.但是踩过坑的却不少. 使用下列代码 @Modifying @Query("update User u set u.firs ...