hdu 1150 Machine Schedule 最小覆盖点集
题意:x,y两台机器各在一边,分别有模式x0 x1 x2 ... xn, y0 y1 y2 ... ym,
现在对给定K个任务,每个任务可以用xi模式或者yj模式完成,同时变换一次模式需要重新启动一次机器,问最少的启动次数
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1150
思路:
稳定转化成给定k条边,使得每一条边最少被一个点覆盖,即最小覆盖点集
最后求出的最大匹配数需要减一才是启动次数,注意到刚开始两台机器都是在0模式下,所以没有0模式,最后就不需要减一
代码:
- #include <iostream>
- #include <string.h>
- using namespace std;
- int m,n,sum;
- int g[][],vis[],who[];
- bool find(int x) {
- for(int i=; i<m; ++i) {
- if(g[x][i]&&!vis[i]) {
- vis[i]=;
- if(who[i]==-||find(who[i])) {
- who[i]=x;
- return true;
- }
- }
- }
- return false;
- }
- int main() {
- //freopen("in.txt","r",stdin);
- //freopen("out.txt","w",stdout);
- ios::sync_with_stdio(false);
- int k,u,v;
- while(cin>>n&&n) {
- cin>>m>>k;
- memset(g,,sizeof(g));
- memset(who,-,sizeof(who));
- int temp,flag=;
- while(k--) {
- cin>>temp>>u>>v;
- if(!u||!v) flag=;
- g[u][v]=;
- }
- sum=;
- for(int i=; i<n; ++i) {
- memset(vis,,sizeof(vis));
- if(find(i)) sum++;
- }
- if(flag) sum--;
- cout<<sum<<endl;
- }
- return ;
- }
hdu 1150 Machine Schedule 最小覆盖点集的更多相关文章
- HDU 1150 Machine Schedule (最小覆盖,匈牙利算法)
题意: 有两台不同机器A和B,他们分别拥有各种运行模式1~n和1~m.现有一些job,需要在某模式下才能完成,job1在A和B上需要的工作模式又可能会不一样.两台机器一开始处于0模式,可以切换模式,但 ...
- 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...
- 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 hdu 1151 Air Raid 匈牙利模版
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
- hdu 1150 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) ...
随机推荐
- Can you solve this equation?
Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its sol ...
- 关于01背包求第k优解
引用:http://szy961124.blog.163.com/blog/static/132346674201092775320970/ 求次优解.第K优解 对于求次优解.第K优解类的问题,如果相 ...
- 定制rpm包---Yum环境搭建
1.1 在yum服务器上创建yum仓库命令 mkdir -p /application/nginx/html/yum cd /application/nginx/html/yum rz #上传rpm包 ...
- IdentityServer4 指定角色授权(Authorize(Roles="admin"))
1. 业务场景 IdentityServer4 授权配置Client中的AllowedScopes,设置的是具体的 API 站点名字,也就是使用方设置的ApiName,示例代码: //授权中心配置 n ...
- 动态引入javascript
注意最后 "</scr"+"ipt>" 这是必要的,因为浏览器只要看到</script>它就会认为代码到此结束,从而引起错误
- JAVAscript学习笔记 js计时器与倒计时 第六节 (原创) 参考js使用表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- linux 安装 Elasticsearch5.6.x 详细步骤以及问题解决方案
在网上有很多那种ES步骤和问题的解决 方案的,不过没有一个详细的整合,和问题的梳理:我就想着闲暇之余,来记录一下自己安装的过程以及碰到的问题和心得:有什么不对的和问题希望及时拍砖. 第一步:环境 li ...
- Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0,"解决办法
这是因为先安装了 .NET Framework 4,随后启用了 .NET Framework 3.5 WCF HTTP 激活,则会发生此错误. 只需要已管理员用户在cmd中运行aspnet_regii ...
- java 通过eclipse编辑器用mysql尝试 连接数据库
注:本人学的是Oracle,用mysql连接数据库是一次尝试. 一.下载JDBC mysql驱动,导入jar包 我自己下载的是connector-java-6.0.6.jar,如下图所示,JD ...
- Mac上编译并运行Android5.0源码
下载.配置环境.build和运行参考的都是Android Source提供的文档,包括:Initializing a Build Environment,Downloading the Source和 ...