Machine Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7362    Accepted Submission(s): 3677

Problem Description
As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here we consider a 2-machine scheduling problem.

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.

 
Input
The 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.

 
Output
The 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
题意:机器A有n种工作方式,B有m中工作方式,有k个工作。给定一个三元组(i,x,y)工作i可以用机器A的x工作方式完成也可以用机器B的y工作方式完成。不过,两个机器没转换一次工作方式均需要重启机器一次。问安排合适的工作次序,最少需要需要重启机器几次?
思路:将机器A的工作方式作为点独立集U,B的工作方式作为点独立集V。工作方式x到y的无向边表示工作i,则问题 转化为求二分图中最小顶点覆盖问题。
#include"cstdio"
#include"cstring"
#include"vector"
using namespace std;
const int MAXN=;
vector<int> G[MAXN];
int V,E;
void add_edge(int u,int v)
{
G[u].push_back(v);
G[v].push_back(u);
}
int match[MAXN];
int vis[MAXN];
bool dfs(int u)
{
vis[u]=;
for(int i=;i<G[u].size();i++)
{
int v=G[u][i],w=match[v];
if(w==||(!vis[w]&&dfs(w)))
{
match[u]=v;
match[v]=u;
return true;
}
}
return false;
} int binpartite_matching()
{
int ans=;
memset(match,,sizeof(match));
for(int i=;i<=V;i++)
{
if(!match[i])
{
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
}
return ans;
} int main()
{
while(scanf("%d",&V)!=EOF&&V)
{
scanf("%*d%d",&E);
for(int i=;i<MAXN;i++) G[i].clear();
for(int i=;i<E;i++)
{
int u,v;
scanf("%*d%d%d",&u,&v);
add_edge(u,+v);
add_edge(+v,u);
}
int ans=binpartite_matching();
printf("%d\n",ans);
} return ;
}

HDU1150(最小顶点覆盖)的更多相关文章

  1. POJ2226 Muddy Fields 二分匹配 最小顶点覆盖 好题

    在一个n*m的草地上,.代表草地,*代表水,现在要用宽度为1,长度不限的木板盖住水, 木板可以重叠,但是所有的草地都不能被木板覆盖. 问至少需要的木板数. 这类题的建图方法: 把矩阵作为一个二分图,以 ...

  2. BZOJ 3140 消毒(最小顶点覆盖)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3140 题意:最近在生物实验室工作的小T遇到了大麻烦. 由于实验室最近升级的缘故,他的分格 ...

  3. poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  4. hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】

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

  5. HDU ACM 1054 Strategic Game 二分图最小顶点覆盖?树形DP

    分析:这里使用树形DP做. 1.最小顶点覆盖做法:最小顶点覆盖 == 最大匹配(双向图)/2. 2.树形DP: dp[i][0]表示i为根节点,而且该节点不放,所需的最少的点数. dp[i][1]表示 ...

  6. hdu1054(最小顶点覆盖)

    传送门:Strategic Game 题意:用尽量少的顶点来覆盖所有的边. 分析:最小顶点覆盖裸题,最小顶点覆盖=最大匹配数(双向图)/2. #include <cstdio> #incl ...

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

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

  8. poj2594最小顶点覆盖+传递闭包

    传递闭包最开始是在Floyd-Warshall算法里面出现的,当时这算法用的很少就被我忽视了.. 传递闭包是指如果i能到达k,并且k能到达j,那么i就能到达j Have you ever read a ...

  9. hdu1151有向图的最小顶点覆盖

    有向图的最小路径覆盖=V-二分图最大匹配. Consider a town where all the streets are one-way and each street leads from o ...

随机推荐

  1. Spring核心(ioc控制反转)

     IoC,Inversion Of Control 即控制反转,由容器来管理业务对象之间的依赖关系,而非传统方式中的由代码来管理. 其本质.即将控制权由应用程序代码转到了外部容器,控制权的转移就是 ...

  2. Lightoj 1088 - Points in Segments 【二分】

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1088 题意: 有一维的n个点和q条线段.询问每条线段上的点有多少个. 思路:寻 ...

  3. redirect_uri 參数错误的解决的方法

    我通过java代码去获得用户的openid,一直报redirect_uri. 我页面代码的链接为: https://open.weixin.qq.com/connect/oauth2/authoriz ...

  4. 取消CentOS 的图形界面 开机直接进入命令行模式(转)

    (1)具体操作   #vi /etc/inittab          –编辑/etc/inittab文件 找到下面语句: # Default runlevel. The runlevels used ...

  5. caffe搭建以及初步学习--win7-vs2013-gtx650tiboost-cuda8.0-cifar10训练和测试-2-快速解决方案cifar10_quick_solver.prototxt

    首先安装好显卡----已经装好了?喜大普奔!没装好?那就用cpu,也是一样的. 拷贝cudnn v5.0 头文件和库文件以及执行文件到cuda8中 -------------------------- ...

  6. xcode升级到6.0以后遇到的警告错误 原帖链接http://www.cocoachina.com/bbs/simple/?t112432.html

    Xcode 升级后,常常遇到的遇到的警告.错误,解决方法 从sdk3.2.5升级到sdk 7.1中间废弃了很多的方法,还有一些逻辑关系更加严谨了.1,警告:“xoxoxoxo”  is depreca ...

  7. 51NOD 1810 连续区间 分治 区间计数

    1810 连续区间 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 80     区间内所有元素排序后,任意相邻两个元素值差为1的区间称为“连续区间” 如:3,1,2是连续区间,但3, ...

  8. Recurrent neural networks are very powerful, because they combine two properties

    https://www.cs.toronto.edu/~hinton/csc2535/notes/lec10new.pdf Distributed hidden state that allows t ...

  9. Android笔记之dp与px之间的转换以及LayoutParams

    dp与px之间的转换公式 px = dp * (dpi / 160) dp = px / (dpi / 160) 其中dpi的获取方式如下 private void getDpi() { Displa ...

  10. 2017NOIP游记 (格式有点炸)

    NOIP游记 作者:一只小蒟蒻 时间可真快呀!还记得我第一次接触信息竞赛时,hello world都要调好久,不知不觉就考完了2017noip,自我感觉良好(虽然还是有很多不足). 这两个月的闭关,让 ...