hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
Machine Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6701 Accepted Submission(s): 3358
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.
The input will be terminated by a line containing a single zero.
#include<stdio.h>
#include<string.h>
#define MAX 1100
int map[MAX][MAX],vis[MAX],mode[MAX];
int t,n,m;
int find(int x)
{
int i,j;
for(i=0;i<m;i++)
{
if(map[x][i]&&vis[i]==0)
{
vis[i]=1;
if(mode[i]==0||find(mode[i]))
{
mode[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int j,i,s,k;
int x,y;
while(scanf("%d",&n),n)
{
memset(map,0,sizeof(map));
memset(mode,0,sizeof(mode));
scanf("%d%d",&m,&k);
while(k--)
{
scanf("%d%d%d",&t,&x,&y);
if(x&&y)
map[x][y]=1;
}
s=0;
for(i=0;i<n;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
s++;
}
printf("%d\n",s);
}
return 0;
}
hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】的更多相关文章
- HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)
Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...
- POJ 1325 && 1274:Machine Schedule 匈牙利算法模板题
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12976 Accepted: 5529 ...
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11958 Accepted: 5094 ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- HDOJ 1150 Machine Schedule
版权声明:来自: 码代码的猿猿的AC之路 http://blog.csdn.net/ck_boss https://blog.csdn.net/u012797220/article/details/3 ...
- hdoj 1054 Strategic Game【匈牙利算法+最小顶点覆盖】
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (step6.3.3)hdu 1150(Machine Schedule——二分图的最小点覆盖数)
题目大意:第一行输入3个整数n,m,k.分别表示女生数(A机器数),男生数(B机器数),以及它们之间可能的组合(任务数). 在接下来的k行中,每行有3个整数c,a,b.表示任务c可以有机器A的a状态或 ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...
随机推荐
- SqlServer日期(convert函数,getdate函数)
SqlServer日期(convert函数,getdate函数) 函数GETDATE()的返回值在显示时只显示到秒.实际上,SQL Sever内部时间可以精确到毫秒级(确切地说,可以精确到3.33毫秒 ...
- PL/SQL学习(一)
原文参考:http://plsql-tutorial.com/ 组成: 声明部分(可选) 执行部分(必选) 异常处理(可选) 声明: DECLARE 执行: ...
- 手机摇一摇效果-html5
1.手机摇一摇效果实现 2.播放声音 <!DOCTYPE html> <html lang="en"> <head> <meta char ...
- php5.3 不支持 session_register() 此函数已启用的解决方法
php从5.2.x升级到5.3.2.出来问题了.有些原来能用的程序报错了,Deprecated: Function session_register() is deprecated php从5.2.x ...
- C#XML创建与节点对象引用
我们在创建xml过程中会遇到不同的级别有相同节点的情况.如下面的xml: <?xml version="1.0" encoding="GBK"> & ...
- mysql 存储引擎 myisam innodb 区别
虽然MySQL里的存储引擎不只是MyISAM与InnoDB这两个,但常用的就是它俩了.可能有站长并未注意过MySQL的存储引擎,其实存储引擎也是数据库设计里的一大重要点,那么博客系统应该使用哪种存储引 ...
- ThinkPHP下使用Ueditor
在做课程设计的时候想到用百度的Ueditor,可在配置的时候出现了一些问题 Ueditor感觉不是很难,以前有个人定制的,现在取消了这项服务,但是我们可以自己进行配置 下载地址:http://uedi ...
- html5音频和视频相关属性和方法
方法 方法 描述 addTextTrack() 为音视频加入一个新的文本轨迹 canPlayType() 检查指定的音视频格式是否得到支持 load() 重新加载音视频标签 play() 播放音视频 ...
- JVM内存管理基本概念
java中是否存在内存泄露? 在Java中,内存泄漏就是存在一些被分配的对象,这些对象有下面两个特点,首先,这些对象是可达的,即在有向图中,存在通路可以与其相连:其次,这些对象是无用的,即程序以后不会 ...
- Swift(二,元组,可选类型,类型转化)
一,首先,元组是Swift中特有的,OC中没有元组相关类型,具体怎么用,看下面的例子吧 //1.使用元组来定义一组数据 let infoTuple = (,1.8) let nameTuple = i ...