hdu1150&&POJ1325 Machine Schedule---最小点覆盖
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1150
题目大意:
给你两台机器A和B,A机器有n种模式,B机器有m种模式,初始时都是0,现在给你k个任务,每个任务可以由机器A的x模式完成或者机器B的y模式完成,而每次改变机器的模式都要重启一次,问你最少的重启次数使得完成所有任务!
解题思路:
首先初始化为0,所以有模式0完成的任务可以不考虑,然后我们可以考虑建立二分图,机器A和机器B的模式互相连接,某个任务由A的x和B的y完成那么x与y相连,所以我们转换下题目的模型就是在这个二分图中找出最少的点使得所有的边都至少有一个端点被选中,而这就是最小点覆盖的模型,而最小点覆盖=最大匹配
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = + ;
const int INF = 1e9;
bool Map[maxn][maxn];
int cx[maxn], cy[maxn];
int cntx, cnty;
bool vis[maxn];
bool dfs(int u)
{
for(int v = ; v <= cnty; v++)
{
if(Map[u][v] && !vis[v])
{
vis[v] = ;
if(cy[v] == - || dfs(cy[v]))
{
cx[u] = v;
cy[v] = u;
return ;
}
}
}
return ;
}
int maxmatch()
{
int ans = ;
memset(cx, -, sizeof(cx));
memset(cy, -, sizeof(cy));
for(int i = ; i <= cntx; i++)
{
if(cx[i] == -)
{
memset(vis, , sizeof(vis));
ans += dfs(i);
}
}
return ans;
}
int main()
{
int n, i, u, v;
while(cin >> cntx && cntx)
{
cin >> cnty >> n;
memset(Map, , sizeof(Map));
while(n--)
{
cin >> i >> u >> v;
Map[u][v] = ;
}
cout<<maxmatch()<<endl;
}
return ;
}
hdu1150&&POJ1325 Machine Schedule---最小点覆盖的更多相关文章
- poj 1325 Machine Schedule 最小点覆盖
题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...
- [poj1325] Machine Schedule (二分图最小点覆盖)
传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...
- POJ1325 Machine Schedule(二分图最小点覆盖集)
最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11958 Accepted: 5094 ...
- POJ1325 Machine Schedule
Description As we all know, machine scheduling is a very classical problem in computer science and h ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule 最少点覆盖
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- POJ-1325 Machine Schedule,和3041有着异曲同工之妙,好题!
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Description As we all know, machine ...
随机推荐
- [Xcode 实际操作]五、使用表格-(5)设置UITableView的单元格背景颜色
目录:[Swift]Xcode实际操作 本文将演示单元格背景颜色的设置 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //首先添加两个协 ...
- web性能优化--缓存
什么是缓存? 缓存(Web缓存)是指代理服务器和客户端本地磁盘保存的资源副本.当 web 缓存发现请求的资源已经被存储,它会拦截请求,返回该资源的拷贝,而不会去源服务器重新下载. 缓存大致可以分为私 ...
- JMETER CSS JQUERY EXTRACTOR
我想如果你在这里,你可能已经访问了我们关于变量提取的JMeter系列: XPath Extractor:使用XPath Expressions从XML响应中提取内容, Regexp Extractor ...
- applicationContext-datasource.xml
<?xml version="1.0" encoding="utf-8"?> <beans default-init-method=" ...
- python_魔法方法(一):构造和析构
魔法方法总是被双下划线包围,例如:__init__() 魔法方法是面向对象的python的一切,它的魔力体现在总能在合适的时候调用. 先来介绍析构和构造的三个魔法方法: __init__():构造方法 ...
- Microsoft JDBC Driver 使用 getParameterMetaData 会报错?
不知道为何使用 Microsoft JDBC Driver for SQL Server 驱动时,sql语句不带参数没有问题,但是如果带参数且使用 getParameterMetaData 就会提示某 ...
- A -- A. Quailty and Playing Cards 模拟 + 思考
http://www.ifrog.cc/acm/problem/1036?contest=1005&no=0 分类,考虑Q神出的是第一张或者是第二张,然后对手出那些牌来应付. Q神出第一张和第 ...
- placeholder-shown
一般我们常见placeholder伪类选择器用来修改默认样式及文案,忽然发现placeholder-shown伪类选择器,比较官方的解释是 CSS伪类表示任何显示占位符文本的form元素. 简单来说就 ...
- java中key值可以重复的map:IdentityHashMap
在Java中,有一种key值可以重复的map,就是IdentityHashMap.在IdentityHashMap中,判断两个键值k1和 k2相等的条件是 k1 == k2 .在正常的Map 实现(如 ...
- Mercurial(HG) Windows+Eclipse安装、配置、使用
Mercurial(HG) Windows客户端安装 Mercurial(HG): http://mercurial.selenic.com/ Windows客户端下载:http://mercuria ...