UVA1194 Machine Schedule
二分图最小覆盖模型的要素
每条边有两个端点,二者至少选择一个。简称 \(2\) 要素。
\(2\) 要素在本题中的体现
每个任务要么在 \(A\) 上以 \(a_i\) 模式执行,要么在机器 \(B\) 上以 \(b_i\) 模式执行。
把 \(A,B\) 的 \(m\) 种模式分别作为 \(m\) 个左部点和右部点,每个任务作为边连接左部 \(a_i\) 节点和右部 \(b_i\) 节点。
求这张二分图的最小覆盖,时间复杂度为 \(O(nm)\) 。
#include <bits/stdc++.h>
using namespace std;
const int N = 106;
int n, m, k, f[N], ans;
bool v[N];
vector<int> e[N];
bool dfs(int x) {
for (unsigned int i = 0; i < e[x].size(); i++) {
int y = e[x][i];
if (v[y]) continue;
v[y] = 1;
if (!f[y] || dfs(f[y])) {
f[y] = x;
return 1;
}
}
return 0;
}
inline void Machine_Schedule() {
cin >> m >> k;
for (int i = 1; i <= n; i++) e[i].clear();
for (int i = 0; i < k; i++) {
int x, y;
scanf("%d %d %d", &i, &x, &y);
e[x].push_back(y);
}
memset(f, 0, sizeof(f));
ans = 0;
for (int i = 1; i <= n; i++) {
memset(v, 0, sizeof(v));
ans += dfs(i);
}
cout << ans << endl;
}
int main() {
while (cin >> n && n) Machine_Schedule();
return 0;
}
UVA1194 Machine Schedule的更多相关文章
- UVA1194 Machine Schedule[二分图最小点覆盖]
题意翻译 有两台机器 A,B 分别有 n,m 种模式. 现在有 k 个任务.对于每个任务 i ,给定两个整数$ a_i\(和\) b_i$,表示如果该任务在 A上执行,需要设置模式为 \(a_i\): ...
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- Machine Schedule
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu-----(1150)Machine Schedule(最小覆盖点)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11958 Accepted: 5094 ...
- HDU 1150:Machine Schedule(二分匹配,匈牙利算法)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- python3.x 和pip3的安装
python3.x 和pip3的安装 本人在学习python3的时候,视频中使用的是python3,在讲解到有些第三方库的时候,无法使用到pip3 install来安装所需的库.由于系统是centos ...
- linux proc
/proc文件系统下的多种文件提供的系统信息不是针对某个特定进程的,而是能够在整个系统范围的上下文中使用.可以使用的文件随系统配置的变化而变化. /proc/cmdline 这个文件给出了内核启动的命 ...
- JAVA核心技术I---JAVA基础知识(列表List)
一:List了解 (一)List:列表 –有序的Collection –允许重复元素 –{,,,{,},,} (二)List:主要实现 同步/非同步:针对线程而言 –ArrayList(非同步的) – ...
- springBootJpa的复杂查询
分页 /** * 条件查询+分页 * @param whereMap * @param page * @param size * @return */ public Page<CaseManag ...
- python 面向对象(一)初识面向对象
##################################总结#################### 1. 面向过程:一切以事物的发展流程为中心 面向对象:一切以对象为中心,一切皆为对向, ...
- Linux记录-监控系统开发
需求:使用shell定制各种个性化告警工具,但需要统一化管理.规范化管理.思路:指定一个脚本包,包含主程序.子程序.配置文件.邮件引擎.输出日志等.主程序:作为整个脚本的入口,是整个系统的命脉.配置文 ...
- 开源图片文字识别引擎——Tesseract OCR
Tessseract为一款开源.免费的OCR引擎,能够支持中文十分难得.虽然其识别效果不是很理想,但是对于要求不高的中小型项目来说,已经足够用了. 文字识别可应用于许多领域,如阅读.翻译.文献资料的检 ...
- cmd命令查看当前IIS运行的网站iisapp appcmd
xp,2003中用的命令是:iisapp -a 2007,2008,2012系统中: cmd命令行进入%windir%\system32\inetsrv\目录下 运行appcmd.exe list w ...
- c++中sizeof的理解
1. 例题 #include <iostream> class A {}; class B { char m_data; }; class C { ]; }; class D { char ...
- java.lang.ClassCastException: com.sun.proxy.$Proxy27 cannot be cast to com.bbk.n002.service.QuestionService
1 严重: Servlet /N002-1.0 threw load() exception 2 java.lang.ClassCastException: com.sun.proxy.$Proxy2 ...