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 ...
随机推荐
- laravel5.4 正式环境 linux 下出现undefined code
1.laravel5.4 正式环境 linux 下出现undefined code问题 报错位置在:登录模块中login 引用 报$_SESSION['code'] 中的code 并未定义 原因: ...
- Python-OpenCV中的图像轮廓检测
目录 cv2.findContours() 主要记录Python-OpenCV中的cv2.findContours()方法:官方文档: cv2.findContours() 在二值图像中寻找图 ...
- bzoj 3944: Sum(杜教筛)
3944: Sum Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 4930 Solved: 1313[Submit][Status][Discuss ...
- Bigdecimal 比较equals与compareTo
原文链接:https://blog.csdn.net/jixinhuluwa/article/details/72626598 1.b.equals(BigDecimal.ZERO); 该方法存在的问 ...
- IDEA的database插件无法链接mysql的解决办法(08001错误)
1.问题 首先先说问题,用navicat链接数据库正常,mysql控制台操作正常,但是用IDEA的数据库插件链接一直报 08001 错误,具体见下图: 错误:Connection to eshop@l ...
- 利用xsltproc转换jtl报告到html报告
使用Jmeter测试完后并不能直接生成html报告,而是jtl报告.这里我们可以用xsltproc来解决. xsltproc是由DanielVeillard用来C语言编写的是一个快速XSLT引擎, ...
- JMeter - REST API测试 - 完整的数据驱动方法(翻译)
https://github.com/vinsguru/jmeter-rest-data-drivern/tree/master 在本文中,我想向您展示一种用于REST API测试的数据驱动方法.如果 ...
- windows下安装python包
1.windows下成功安装好python后,在安装目录的Scripts目录下有easy_install和pip工具 2.如果没有安装pip,进入命令行,切换到python的安装目录下的Scripts ...
- ACM 大神的经验加技巧(当然不是我的拉——
大神 犯错合集及需要注意的东西 1.在一个地图求最大面积的类问题中,要注意障碍结点的影响. 2.ll(),表示的是在运算后把括号内强制转化为类型ll,而(ll)表示后面的每个玩意都强制转化为类型ll. ...
- (转)Linux之split命令详解
Linux之split命令详解 原文:http://m.jb51.net/article/73632.htm Linux split命令用于将一个文件分割成数个,该指令将大文件分割成较小的文件,在默认 ...