POJ 1325 && ZOJ 1364--Machine Schedule【二分图 && 最小点覆盖数】
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 13071 | Accepted: 5575 |
Description
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
x, y.
The input will be terminated by a line containing a single zero.
Output
Sample Input
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
Sample Output
3
题意:
有A,B两台机器。机器A有 n种工作模式,分别为 mode_0,mode_1,mode_2.....,机器B有 m种工作模式,分别为 mode_0,mode_1。mode_2.....。刚開始A。B的工作模式都是mode_0。
给定K个任务。表示为(i 。x。y),意思是作业 i 能够工作在机器A的mode_x模式或者机器B的mode_y的模式。
为了完毕全部的工作,必须时不时的切换机器的工作模式,但机器工作模式的切换仅仅能通过重新启动机器完毕,问你最少重新启动多少次机器。才干把工作分配完。
解析:
一看有A ,B种机器,再依据题意,两种机器有匹配关系,我们首先构造二分图,把A的n个mode和B的m个mode看做图的顶点。假设某个任务能够在A的mode_i 或B的mode_j 上完毕。则从Ai 到 Bj连一条边,这样就构成了二分图。
由题意可知,本意要求的是二分图的最小点覆盖集问题,即最小的顶点集合,“覆盖”全部的边,能够转化成二分图的最大匹配问题。
二分图的最小点覆盖数 == 最大匹配数。
另外要注意,机器A 和机器B最初都是在mode_0。所以对那些能够在机器A的mode_0或者机器B的模式_0工作的作业,在完毕这些作业时是不须要重新启动机器的。
一開始没考虑这里。贡献了一次wa。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 110
using namespace std; int map[maxn][maxn];
int used[110];
int link[maxn];
int n, m, k; void getmap(){
while(k--){
int c, a, b;
scanf("%d%d%d", &c, &a, &b);
if(a == 0 || b == 0) continue;
map[a][b] = 1;
}
} bool dfs(int x){
for(int i = 0; i < m; ++i){
if(!used[i] && map[x][i]){
used[i] = 1;
if(link[i] == -1 || dfs(link[i])){
link[i] = x;
return true;
}
}
}
return false;
} int hungary(){
int ans = 0;
memset(link, -1, sizeof(link));
for(int i = 0; i < n; ++i){
memset(used, 0, sizeof(used));
if(dfs(i))
ans++;
}
return ans;
} int main (){
while(scanf("%d", &n), n){
scanf("%d%d", &m, &k);
memset(map, 0, sizeof(map));
getmap();
int sum = 0;
sum = hungary();
printf("%d\n", sum);
}
return 0;
}
POJ 1325 && ZOJ 1364--Machine Schedule【二分图 && 最小点覆盖数】的更多相关文章
- ZOJ 1364 Machine Schedule(二分图最大匹配)
题意 机器调度问题 有两个机器A,B A有n种工作模式0...n-1 B有m种工作模式0...m-1 然后又k个任务要做 每一个任务能够用A机器的模式i或b机器的模式j来完毕 机器開始都处于模式0 每 ...
- HDU1150 Machine Schedule(二分图最大匹配、最小点覆盖)
As we all know, machine scheduling is a very classical problem in computer science and has been stud ...
- HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)
Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...
- hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ - 1325 Machine Schedule 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
- [poj1325] Machine Schedule (二分图最小点覆盖)
传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...
- HDU 1150 Machine Schedule (二分图最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...
- (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 (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
随机推荐
- Spring深入浅出(四)AOP面向切面
面向切面编程--AOP AOP(Aspect Oriented Programming),程序员称之为面向切面编程,是Spring框架除了IOC之外的另一个核心概念. AOP是对OOP(面向对象编程) ...
- NodeJS学习笔记 (26)命令行设计-repl
https://github.com/chyingp/nodejs-learning-guide
- iOS开发—— Couldn't add the Keychain Item
报错:*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn ...
- JS文字特效:彩色滚动变幻效果,只适合少量的文字。(过多对页面有影响)
JS代码如下: 代码具体是在哪里的我不知道但是我的有道云上有.如有哪位朋友知道,还望联系下,添加出处. <div id="chakhsu"></div> & ...
- 一个Web报表项目的性能分析和优化实践(二):MySQL数据库连接不够用(TooManyConnections)问题的一次分析和解决案例
最近,项目中遇到了数据库连接不够的问题. 异常信息com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data ...
- 题解 CF1037D 【Valid BFS?】
不管怎么说,这都不是道紫题吧... 这里采用的思想有点类似轻重链剖分. 我们按照每个节点在序列里面出现的顺序,把每一个节点连出去的边都排一个序. 这样(如果序列没错)肯定会按照序列的方式遍历完全图. ...
- POJ1158 城市交通Traffic lights IOI 1999 (最短路)
POJ1158 城市交通Traffic lights IOI 1999 (最短路) (1) 问题描述(probolem) 在d城里交通的安排不同寻常,城中有路口和路口之间的道路,再任意两个不同的路口之 ...
- AndroidMainfest.xml具体解释——<activity>
语法: <activity android:allowEmbedded=["true" | "false"] android:allowTaskRepar ...
- HDU 4572 Bottles Arrangement
具体的证明:点击打开链接 我的想法: 要想保证题目所说 构造最小行的和,仅仅能是这样的情况 ..... m-3 m-2 m-1 m | m m-1 m-2 m-3 ...
- 利用opencv源代码和vs编程序训练分类器haartraining.cpp
如需转载请注明本博网址:http://blog.csdn.net/ding977921830/article/details/47733363. 一 训练框架 训练人脸检測分类器须要三个步骤: (1 ...