题目大意: 
有两台机器A和B以及K个需要运行的任务。A机器有N种不同的模式,B机器有M种不同的模式,而每个任务都恰好在一台机器上运行。 
如果它在机器A上运行,则机器A需要设置为模式xi,如果它在机器B上运行,则机器A需要设置为模式yi。 
每台机器上的任务可以按照任意顺序执行,但是每台机器每转换一次模式需要重启一次。请合理为每个任务安排一台机器并合理安排顺序,使得机器重启次数尽量少。

题解:
把机器A的N种模式作为二分图的左部,机器B的M种模式作为二分图的右部,如果某个任务可以使用机器A的模式xi也可以使用机器B的模式yi完成,则连接xi,yi。 
由于要使得机器重启的次数最少而又要完成所有的任务,题目转化为从这N+M个点中取出最少数量的点覆盖所有的边。 
又根据二分图的性质:最小点覆盖=最大匹配数,可以使用匈牙利算法求出答案

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstring>
#define pau putchar(' ')
#define ent putchar('\n')
#define mse(a,b) memset(a,b,sizeof(a))
#define ren(x) for(ted*e=fch[x];e;e=e->nxt)
#define rep(i,s,t) for(int i=s,__=t;i<=__;i++)
#define dwn(i,s,t) for(int i=s,__=t;i>=__;i--)
using namespace std;
const int maxn=+,maxm=+;
int lnk[maxn];bool vis[maxn];
struct ted{int x,y;ted*nxt;}adj[maxm],*fch[maxn],*ms=adj;
void add(int x,int y){*ms=(ted){x,y,fch[x]};fch[x]=ms++;return;}int n,m,k;
bool match(int x){
ren(x){int v=e->y;if(!vis[v]){vis[v]=true;
if(!lnk[v]||match(lnk[v])){lnk[v]=x;return true;}
}
}return false;
}
int hungary(){
mse(lnk,false);int ans=;rep(i,,n){mse(vis,false);if(match(i))ans++;}return ans;
}
inline int read(){
int x=;bool sig=true;char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=false;
for(;isdigit(ch);ch=getchar())x=*x+ch-'';return sig?x:-x;
}
inline void write(int x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=;static int buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
int main(){
while(true){
n=read();if(!n)break;
mse(fch,NULL);ms=adj;
m=read();k=read();int x,y;
rep(i,,k){
read();x=read();y=read();if(x&&y)add(x,y);
}write(hungary());ent;
}
return ;
}

HDU 1150 Machine Schedule的更多相关文章

  1. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

  2. hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...

  3. hdu 1150 Machine Schedule(最小顶点覆盖)

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  4. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  5. hdu 1150 Machine Schedule 最少点覆盖

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  6. hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版

    //两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...

  7. hdu 1150 Machine Schedule (二分匹配)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDU——1150 Machine Schedule

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule

    二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...

  10. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

随机推荐

  1. python 面向对象简单理解

    面向对象: 是一种程序设计范型 作用: 提高软件的重用性和灵活性,扩展性 世界万物一切皆为对象,对象即是指由特定状态,特征,行为的实体   知识点一: 代码的重用 举个栗子 比如小月月有了一个女朋友1 ...

  2. 还原或删除sql server 2008数据库时,经常烩出现: “因为数据库正在使用,所以无法获得对数据库的独占访问权”,终解决方案

    还原或删除sql server 2008数据库时,经常烩出现: “因为数据库正在使用,所以无法获得对数据库的独占访问权”,终解决方案如下 关键SQL语句: ALTER DATABASE [dateba ...

  3. Unity3D获取当前键盘按键

    获取当前键盘按键,代码如下: using UnityEngine; using System.Collections; public class GetCurrentKey : MonoBehavio ...

  4. 一个jquery的图片下拉列表 ddSlick

    [ddSlick]http://designwithpc.com/Plugins/ddSlick How to use with JSON data Include the plugin javasc ...

  5. RESTful 架构风格概述

    http://blog.igevin.info/posts/restful-architecture-in-general/(非常好) http://blog.igevin.info/posts/re ...

  6. shell脚本学习之Bash shell 里各种括号的用法

    今天在 SegmentFault 上看到又有人问起关于Shell里各种括号的问题.对于很多玩Shell的人,括号是个很尴尬的问题,用起来没问题,说起来不明白,我在这里总结一下Bash Shell几种括 ...

  7. winform中的chat

    百度一下 源代码下载:百度一下

  8. windows8一直更新不了的问题————解决方案

    以下是微软官方工程师的详细解答: 尊敬的佐先生: 您好! 感谢您联系微软技术支持!我是微软技术支持工程师,我姓张.我将协助您解决有关问题.您的问题编号是SRX 1274238225 对于您当前的更新问 ...

  9. who am i

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...

  10. Java学习----字符串函数

    1.String string类是最终类,不可以有子类 package com.demo.pkg1; public class TestString { public static void main ...