hdu1150——最小点覆盖
There are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1, …, mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1, … , mode_m-1. At the beginning they are both work at mode_0.
For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode_3 or in machine B at mode_4, job 1 can either be processed in machine A at mode_2 or in machine B at mode_4, and so on. Thus, for job i, the constraint can be represent as a triple (i, x, y), which means it can be processed either in machine A at mode_x, or in machine B at mode_y.
Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the times of restarting machines.
InputThe input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i, x, y.
The input will be terminated by a line containing a single zero.
OutputThe output should be one integer per line, which means the minimal times of restarting machine.
Sample Input
5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0
Sample Output
3 大意:两个机器,分别有N个和M个模式,K个工作,每个工作可以用第一个机器的某个模式完成或者用第二个机器的某个模式完成。每次机器切换模式都需要重新启动。
问最少重启几次机器。
这是一个裸的最小点覆盖,还是求一个图中与每条边相邻的最小点集。最大匹配=最小点覆盖
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int read(){
int xx=,ff=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')ff=-;ch=getchar();}
while(ch>=''&&ch<=''){xx=(xx<<)+(xx<<)+ch-'';ch=getchar();}
return xx*ff;
}
const int maxn=;
int lin[maxn],len,N,M,K,ans;
struct edge{
int y,next;
}e[];
inline void insert(int xx,int yy){
e[++len].next=lin[xx];
e[len].y=yy;
lin[xx]=len;
}
int tim,pretim,match[maxn],vis[maxn];
bool hun(int x){
for(int i=lin[x];i;i=e[i].next)
if(vis[e[i].y]<=pretim){
vis[e[i].y]=++tim;
if(match[e[i].y]==||hun(match[e[i].y])){
match[e[i].y]=x;
match[x]=e[i].y;
return ;
}
}
return ;
}
int main(){
//freopen("in","r",stdin);
//freopen("out","w",stdout);
while(){
N=read();
if(!N)
break;
M=read(),K=read();
memset(lin,,sizeof(lin));len=;
for(int i=;i<=K;i++){
read();
int t1=read(),t2=read();
insert(t1,t2+N);
}
ans=;tim=;pretim=;
memset(match,,sizeof(match));
memset(vis,,sizeof(vis));
for(int i=;i<=N+M;i++)
if(!match[i]){
pretim=tim;
vis[i]=++tim;
if(hun(i))
ans++;
}
printf("%d\n",ans);
}
return ;
}
hdu1150——最小点覆盖的更多相关文章
- HDU1150 Machine Schedule(二分图最大匹配、最小点覆盖)
As we all know, machine scheduling is a very classical problem in computer science and has been stud ...
- 【hdu1150】【Machine Schedule】二分图最小点覆盖+简单感性证明
(上不了p站我要死了,侵权度娘背锅) 题目大意 有两台机器A和B以及N个需要运行的任务.每台机器有M种不同的模式,而每个任务都恰好在一台机器上运行.如果它在机器A上运行,则机器A需要设置为模式ai,如 ...
- ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)
//匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...
- 【POJ 3041】Asteroids (最小点覆盖)
每次选择清除一行或者一列上的小行星.最少选择几次. 将行和列抽象成点,第i行为节点i+n,第j列为节点j,每个行星则是一条边,连接了所在的行列. 于是问题转化成最小点覆盖.二分图的最小点覆盖==最大匹 ...
- POJ 2226 最小点覆盖(经典建图)
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8881 Accepted: 3300 Desc ...
- nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...
- [USACO2005][POJ2226]Muddy Fields(二分图最小点覆盖)
题目:http://poj.org/problem?id=2226 题意:给你一个字符矩阵,每个位置只能有"*"或者“.",连续的横着或者竖的“*"可以用一块木 ...
- POJ3041Asteroids(最小点覆盖+有点小抽象)
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18289 Accepted: 9968 Descri ...
- hdu 1054 最小点覆盖
Sample Input 4 0:(1) 1 1:(2) 2 3 2:(0) 3:(0) 5 3:(3) 1 4 2 1:(1) 0 2:(0) 0:(0) 4:(0) Sample Output ...
随机推荐
- java网络
title: java 网络 date: 2017年3月11日11:14:52 1. 复杂的东西就把他封装成对象 概述:(网络就是找到别人) 找到对方的机器,(找到对方的ip地址) 每个机器中有很多进 ...
- ELK基本统计图表
ELK基本统计图表,现在基本在用自带的功能,复杂的功能还需要去摸索了
- js post一个对象 在C#中怎么接收? 未解决
这个在C#中怎么接收?
- 在把table表格中的数据导出到Excel的时候,以科学计数法显示位数多的数字时怎么解决?
sbHtml.AppendFormat("<td> {0}</td>", data[i].IDcard.ToString()); sbHtml.Append ...
- day04-交互、格式化输出及基本运算符
目录 与用户交互 python2和python3交互的区别 格式化输出 1 字符串拼接 2 占位符 3 format格式 4 f-string格式 基本运算符 算术运算符 比较运算符 赋值运算符 逻辑 ...
- jenkins配置邮件通知
参考: https://www.cnblogs.com/imyalost/p/8781759.html 谢谢大佬~
- 通过git向github提交项目
按顺序学习 https://www.cnblogs.com/forget406/p/6045499.html#top https://blog.csdn.net/xiaoputao0903/artic ...
- Redis防护建议
1.Redis本身防护 (1)不要使用默认端口(6379) (2)增加Redis用户名和密码 (3)在Redis绑定指定IP访问(位置配置文件[redis.config]中的bind节点)2.L ...
- 爬虫文件存储-2:MongoDB
1.连接MongoDB 连接 MongoDB 我们需要使用 PyMongo 库里面的 MongoClient,一般来说传入 MongoDB 的 IP 及端口即可,第一个参数为地址 host,第二个参数 ...
- raspberry 重新烧录后的设置
raspberry初学者在使用的时候经常遇到各种问题,常常重新烧录系统,现在把新系统的常用配置和安装内容整理一下,避免自己忘记 1.安装常用软件包: sudo apt-get gedit sudo a ...