POJ - 1325 Machine Schedule 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式。假设要切换模式的话,机器就必须的重新启动 
有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完毕,问要重新启动多少次机器才干完毕任务
解题思路:两个机器的点分为两个点集。点集之间的关系就是任务了。要将全部任务都完毕。就要将全部边都覆盖掉,所以就是求最小点覆盖了。
这里有一个点要注意。假设全部任务中都有一个0,那么机器就不用重新启动了,重新启动次数就为0了(由于刚開始都是0)
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
const int N = 110;
int n, m, k;
int vis[N], link[N];
bool flag;
vector<int> g[N];
void init() {
    for(int i = 1; i < n; i++)
        g[i].clear();
    int x, y, z;
    for(int i = 0; i < k; i++) {
        scanf("%d%d%d", &x, &y, &z);
        if(y * z == 0)
            continue;
        g[y].push_back(z);
    }
    memset(link, -1, sizeof(link));
}
bool dfs(int u) {
    for(int i = 0; i < g[u].size(); i++) {
        int v = g[u][i];
        if(vis[v])
            continue;
        vis[v] = 1;
        if(link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            return true;
        }
    }
    return false;
}
void hungary() {
    int ans = 0;
    for(int i = 1; i < n; i++) {
        memset(vis, 0, sizeof(vis));
        if(dfs(i))
            ans++;
    }
    printf("%d\n",ans);
}
int main() {
    while(scanf("%d", &n) != EOF && n) {
        scanf("%d%d", &m, &k);
        init();
        hungary();
    }
    return 0;
}POJ - 1325 Machine Schedule 二分图 最小点覆盖的更多相关文章
- POJ 1325 Machine Schedule(最小点覆盖)
		http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ... 
- UVA1194 Machine Schedule[二分图最小点覆盖]
		题意翻译 有两台机器 A,B 分别有 n,m 种模式. 现在有 k 个任务.对于每个任务 i ,给定两个整数$ a_i\(和\) b_i$,表示如果该任务在 A上执行,需要设置模式为 \(a_i\): ... 
- [poj1325] Machine Schedule (二分图最小点覆盖)
		传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ... 
- HDU 1150 Machine Schedule (二分图最小点覆盖)
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ... 
- POJ 1325 Machine schedine (二分图-最小点覆盖数=最大匹配边数)
		As we all know, machine scheduling is a very classical problem in computer science and has been stud ... 
- [POJ] 2226 Muddy Fields(二分图最小点覆盖)
		题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ... 
- poj 1325 Machine Schedule 最小点覆盖
		题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ... 
- HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)
		Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ... 
- POJ 1325 Machine Schedule(zoj 1364) 最小覆盖数
		http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=364 http://poj.org/problem?id=1325 题目大意: ... 
随机推荐
- spring @Transactional注解无效
			<!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jd ... 
- j.u.c系列(01) ---初探ThreadPoolExecutor线程池
			写在前面 之前探索tomcat7启动的过程中,使用了线程池(ThreadPoolExecutor)的技术 public void createExecutor() { internalExecutor ... 
- 修改WampServer的默认端口
			WampServer默认的安装端口是80,容易和已安装的ISS等其他服务冲突,导致WampServer无法启动. 无法启动的现象如下: 1.apache服务无法启动.问题所在:80端口冲突. 2.在浏 ... 
- 绝对定位的div的居中方法,下面的写法兼容IE系列浏览器和火狐浏览器。
			详细解说,直接看样式:#dingwei{padding:10px;background-color:#003300;color:#FFFFFF; width:600px;height:300px; d ... 
- 实现观察者模式(Observer Pattern)的2种方式
			在观察者模式中有2个要素:一个是被观察对象,另一个是观察者.但被观察对象的状态发生改变会通知观察者. 举例:把订阅报纸的人看作是观察者,把报纸看作被观察对象.每当有新的新闻就要通知订阅报纸的人.本篇分 ... 
- extjs 动态设定 DateField 最大值 最小值
			yxrqDate.minValue = new Date();yxrqDate.maxValue = new Date(9000,1,1);yxrqDate.validate(); //var pic ... 
- EntityFramework(EF)贪婪加载和延迟加载的选择和使用
			贪婪加载:顾名思议就是把所有要加载的东西一 次性读取 1 using (var context = new MyDbContext()) 2 { 3 var orders = from o in co ... 
- 使用开源库 EasyTimeline 操作定时器 NSTimer
			EasyTimeline https://github.com/mmislam101/EasyTimeline Sometimes you need things to happen at speci ... 
- kafka系列文章索引(结束)
			apache kafka在数据处理中特别是日志和消息的处理上会有很多出色的表现,这里写个索引,关于kafka的文章暂时就更新到这里,最近利用空闲时间在对 kafka做一些功能性增强,并java化,虽然 ... 
- 26个Jquery1.4使用小技巧
			1. 禁止右键点击 1. $(document).ready(function(){ 2. $(document).bind("contextmenu&quo ... 
