HDU 1150:Machine Schedule(二分匹配,匈牙利算法)
Machine Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5371 Accepted Submission(s): 2658
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.
x, y.
The input will be terminated by a line containing a single zero.
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
3
这题和过山车一模一样。。
就是多了点无用的东西。
。水。。
。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; const int M = 1000 + 5;
int n, m, k, cas;
int link[M];
bool MAP[M][M];
bool cover[M];
int ans; void init()
{
int x, y;
memset(MAP, false, sizeof(MAP));
for(int i=0; i<k; i++)
{
scanf("%d %d %d", &cas, &x, &y);
if(x&&y)
MAP[x][y]=true;
}
} bool dfs(int x)
{
for(int y=1; y<=m; y++)
{
if(MAP[x][y] && !cover[y])
{
cover[y]=true;
if(!link[y] || dfs(link[y]))
{
link[y]=x;
return true;
}
}
}
return false;
} int main()
{
while(scanf("%d", &n) && n)
{
ans=0;
memset(link, 0, sizeof(link));
scanf("%d %d", &m, &k);
init();
for(int i=1; i<=n; i++)
{
memset(cover, false, sizeof(cover));
if( dfs(i) )
ans++;
}
printf("%d\n", ans);
} return 0;
}
HDU 1150:Machine Schedule(二分匹配,匈牙利算法)的更多相关文章
- HDU 1150 Machine Schedule (最小覆盖,匈牙利算法)
题意: 有两台不同机器A和B,他们分别拥有各种运行模式1~n和1~m.现有一些job,需要在某模式下才能完成,job1在A和B上需要的工作模式又可能会不一样.两台机器一开始处于0模式,可以切换模式,但 ...
- 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 ...
- 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 ...
- 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule
二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...
- hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 【01染色法判断二分匹配+匈牙利算法求最大匹配】HDU The Accomodation of Students
http://acm.hdu.edu.cn/showproblem.php?pid=2444 [DFS染色] #include<iostream> #include<cstdio&g ...
- hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
随机推荐
- spring学习总结(mybatis,事务,测试JUnit4,日志log4j&slf4j,定时任务quartz&spring-task,jetty,Restful-jersey等)
在实战中学习,模仿博客园的部分功能.包括用户的注册,登陆:发表新随笔,阅读随笔:发表评论,以及定时任务等.Entity层设计3张表,分别为user表(用户),essay表(随笔)以及comment表( ...
- Android 4.4及以上系统下应用的状态栏颜色渐变效果的实现
上一篇转载的博文里讲到了怎么开启状态栏透明的效果,不过如果在有ActionBar的情况下,会出现状态栏透明而ActionBar横亘在状态栏和内容之间的丑陋情况,如下图: 通过百度之后,发现了GitHu ...
- HDU 4705 Y
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submis ...
- MVC 常用方法
1. 后台 action方法里添加错误消息到字典中(key,value) ModelState.AddModelError("Error", "参数传输有误,请重新尝试! ...
- java线程之停止线程
在Java中有以下3种方法可以终止一个正在运行的线程: 1.使用退出标志,是线程正常退出,也就是run方法完成后线程终止. 2.使用stop方法强制终止线程,但不推荐使用 ...
- 关于PagedDataSource分页属性与DataSet和DataTable详解
Asp.net提供了三个功能强大的列表控件:DataGrid.DataList和Repeater控件,但其中只有DataGrid控件提供分页功能.相对DataGrid,DataList和Repeate ...
- 「OC」类的深入研究、description方法和sel
一.类的深入研究 (一)类的本质 类本身也是一个对象,是class类型的对象,简称“类对象”. Class类型的定义: Typedef struct obj class *class; 类名就代表着类 ...
- jQuery $.fn.extend方式自定义插件
之前例子是扩展jQuery的工具方法,即通过$.xxx(para);的形式来使用的.下面是扩展jquery对象的方法,即任意一个jquery对象都已访问. 具体如下: wyl.js: (functio ...
- [LeetCode]题解(python):063-Unique Paths II
题目来源: https://leetcode.com/problems/unique-paths-ii/ 题意分析: 这题的规则和上一题一样.给一个m×n的矩阵0,1矩阵.0代表可以经过,1代表不可以 ...
- 入门前端之HTML
本文内容: HTML概念 HTML元素 HTML属性 HTML标题 HTML段落 HTML格式化 HTML样式 HTML 链接 HTML 图像 HTML 表格 HTML 列表 HTML 块 HTML ...