ZOJ 1364 Machine Schedule(二分图最大匹配)
题意 机器调度问题 有两个机器A,B A有n种工作模式0...n-1 B有m种工作模式0...m-1 然后又k个任务要做 每一个任务能够用A机器的模式i或b机器的模式j来完毕 机器開始都处于模式0 每次换模式时都要重新启动 问完毕全部任务机器至少重新启动多少次
最基础的二分图最大匹配问题 对于每一个任务把i和j之间连一条边就能够构成一个二分图 那么每一个任务都能够相应一条边 那么如今就是要找最少的点 使这些点能覆盖全部的边 即点覆盖数 又由于二分图的点覆盖数 = 匹配数 那么就是裸的求二分图最大匹配问题了 两边的点数都不超过100直接DFS增广即可了
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int g[N][N], a[N], b[N], vis[N];
int n, m, k, ans; int dfs(int i) //DFS增广
{
for(int j = 1; j < m; ++j)
{
if(g[i][j] && !vis[j])
{
vis[j] = 1;
if( b[j] == -1 || dfs(b[j]))
{
//机器a的模式i与机器b的模式j匹配
a[i] = j;
b[j] = i;
return 1;
}
}
}
return 0;
} int main()
{
int u, v, t;
while(scanf("%d", &n), n)
{
memset(g, 0, sizeof(g));
scanf("%d%d", &m, &k);
for(int i = 0; i < k; ++i)
{
scanf("%d%d%d", &t, &u, &v);
g[u][v] = 1;
} ans = 0;
memset(a, -1, sizeof(a));
memset(b, -1, sizeof(b));
//状态0不须要重新启动 所以能够忽略0
for(int i = 1; i < n; ++i)
{
if(a[i] == -1) //i没被匹配 以i为起点找一条增广路
{
memset(vis, 0, sizeof(vis));
ans += dfs(i); //
}
} printf("%d\n", ans);
}
return 0;
}
//Last modified : 2015-07-10 14:50
Machine Schedule
Time Limit: 2 Seconds Memory Limit: 65536 KB
As 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
The 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.
Output
The output should be one integer per line, which means the minimal times of restarting machine.
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
ZOJ 1364 Machine Schedule(二分图最大匹配)的更多相关文章
- HDU1150 Machine Schedule(二分图最大匹配、最小点覆盖)
As we all know, machine scheduling is a very classical problem in computer science and has been stud ...
- UVA1194 Machine Schedule[二分图最小点覆盖]
题意翻译 有两台机器 A,B 分别有 n,m 种模式. 现在有 k 个任务.对于每个任务 i ,给定两个整数$ a_i\(和\) b_i$,表示如果该任务在 A上执行,需要设置模式为 \(a_i\): ...
- HDU 1150 Machine Schedule (二分图最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- [poj1325] Machine Schedule (二分图最小点覆盖)
传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...
- POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题
POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...
- poj 2724 Purifying Machine(二分图最大匹配)
题意: 有2^N块奶酪,编号为00...0到11..1. 有一台机器,有N个开关.每个开关可以置0或置1,或者置*.但是规定N个开关中最多只能有一个开关置*. 一旦打开机器的开关,机器将根据N个开关的 ...
- (step6.3.3)hdu 1150(Machine Schedule——二分图的最小点覆盖数)
题目大意:第一行输入3个整数n,m,k.分别表示女生数(A机器数),男生数(B机器数),以及它们之间可能的组合(任务数). 在接下来的k行中,每行有3个整数c,a,b.表示任务c可以有机器A的a状态或 ...
- POJ - 1325 Machine Schedule 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
随机推荐
- android 图片上传到服务端 文件损坏问题
在网上找的例子,怎么试都不行. 上传上去之后提示文件损坏,不过最后问题还是找到了. 是因为不能在写入流的byte中写入其他内容 这是网上的例子 如果是要在服务端取文件名,可以在这里写入 在服务端获取文 ...
- Coherence的集群成员的离开和加入机制研究
最近在客户那里环境中coherence集群不稳定,所以找出一些文档,需要搞清楚Coherence内部的一些机制 1.集群成员的离开 关于状态的检测,官方的说法是: Death detection is ...
- leetcode笔记:Word Ladder
一. 题目描写叙述 Given two words (start and end), and a dictionary, find the length of shortest transformat ...
- Delphi 最小化程序到任务栏托盘 增加右键PopMenu
在做中间层时,中间层往往不需要点击关闭时立刻关闭,而是最小化到托盘.故而特意隐藏关闭按钮功能. 1)隐藏退出功能 用PopMenu退出菜单代替 1.增加popMenu退出菜单,绑定到窗体 2.增加变量 ...
- CentOS7下nrpe3.0安装(转)
本人菜鸟一枚,在学习nagios的时候碰到了很多问题,在网上找了很多相关的教程,都是老版本的,怎么装都不对,强迫症的我非要按装新版本,老版本的教程怎么搞都不行,只能自己研究了. 首先,下载nrpe3. ...
- javascript快速入门22--Ajax简介
Ajax是什么? 首先,Ajax是什么?一个很酷的新兴词汇!仅仅是某种早就有了的技术的一种新说法而已! Ajax是指一种创建交互式网页应用的网页开发技术.要谈到网页应用程序,则必须从WEB的历史来讲: ...
- Spark(十一) -- Mllib API编程 线性回归、KMeans、协同过滤演示
本文测试的Spark版本是1.3.1 在使用Spark的机器学习算法库之前,需要先了解Mllib中几个基础的概念和专门用于机器学习的数据类型 特征向量Vector: Vector的概念是和数学中的向量 ...
- sqoop操作与使用
sqoop只要安装到集群中的一台节点就可以了 1.上传sqoop到节点中 2.安装和配置 在添加sqoop到环境变量到/etc/profile中 将数据库连接驱动拷贝到$SQOOP_HOME/lib里 ...
- 【Android高级】应用开发必需要掌握的框架<Volley>
开发久了,就会发现掌握一个好的应用框架是多么的重要,尽管是别人的东西,你或许不能全然搞懂当中的原理,但你知道怎样利用其到自己的开发中,这样不仅能节省大量的时间.并且别人沉淀下来的精华效果一定比他的厉害 ...
- 手机SD卡损坏补救措施
现在的应用程序越来越重,比如微信.来往之类的,稍微用一段时间,就会占用几十MB甚至上百MB的空间.而有时候甚至手机会出现"无响应"的现象,需要你选择"继续等待" ...