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/ ...
随机推荐
- bounds的深入研究
一.bounds的深入研究 1>frame:是以父控件的左上角为原点,描述的是一块区域的可视范围, bounds:是以自己内容左上角为原点,描述的是可视范围在内容范围显示的区域 2> ...
- 2016030207 - sql50题练习(脚本)
我的mysql版本是5.下面是要进行sql练习题使用的脚本.脚本是我整理出来的,在我本地直接复制执行就可以使用! 参考网址是:http://blog.csdn.net/zhangyulin54321/ ...
- 代码块(block)简介
代码块是对C语言中函数的扩展,由C语言实现,所以在以C为基础的语言内都是有效的,包括Objective_C,C++和Objective-C++,在Xcode的GCG与Clang工具中是有效的,但这不属 ...
- STM32系列命名规则
转自:STM32系列命名规则 STM32 F 103 C 6 T 7 xxx 1 2 3 4 5 6 7 8 第1部分:产品系列名,固定为STM32 第2部分:产品类型:F表示这是Flash产品,目前 ...
- java版 正文抽取 基于文字连接比
package cn.tdt.crawl.jdbc; import java.util.regex.Matcher; import java.util.regex.Pattern; import or ...
- front-end
http://info.1688.com/detail/1139720782.html http://segmentfault.com/q/1010000000136513 http://h5apps ...
- Ubuntu 14.04安装Chromium浏览器并添加Flash插件Pepper Flas
转自Ubuntu 14.04安装Chromium浏览器并添加Flash插件Pepper Flash Player Chromium谷歌的开源浏览器将不再支持Netscape浏览器插件API,Adobe ...
- 【poj3734】矩阵乘法求解
[题意] 给N个方块排成一列.现在要用红.蓝.绿.黄四种颜色的油漆给这些方块染色.求染成红色方块和染成绿色方块的个数同时为偶数的染色方案的个数,输出对10007取余后的答案.(1<=n<= ...
- 【CF】259 Div.1 B Little Pony and Harmony Chest
还蛮有趣的一道状态DP的题目. /* 435B */ #include <iostream> #include <string> #include <map> #i ...
- Benefits of Cold Showers: 7 Reasons Why Taking Cool Showers Is Good For Your Health
Benefits of Cold Showers: 7 Reasons Why Taking Cool Showers Is Good For Your Health Most of us have ...