hdu 1150 Machine Schedule 最少点覆盖

时间:2022-12-18 10:52:48

Machine Schedule

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1150

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

HINT

题意

有2个机器m个任务,每一个任务在a机器需要状态x,在b机器需要状态y,然后每个机器开始状态都是0,改变状态花费为1,然后问你最小花费完成这些任务

题解:

把每一个任务都当成一个边,把x状态和y连接起来,然后就是求最小的点来覆盖所有的边,就是一个最少点覆盖问题

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//************************************************************************************** inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int ma[maxn][maxn];
int vis[maxn];
int match[maxn];
int n,m;
vector<int> e[maxn];
int dfs(int a)
{
for(int i=;i<e[a].size();i++)
{
if(vis[e[a][i]]==)
{
vis[e[a][i]]=;
if(match[e[a][i]]==-||dfs(match[e[a][i]]))
{
match[e[a][i]]=a;
return ;
}
}
}
return ;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==)
break;
memset(match,-,sizeof(match));
for(int i=;i<n;i++)
e[i].clear();
m=read();
int k=read();
for(int i=;i<k;i++)
{
int a=read();
int x=read(),y=read();
if(x>&&y>)
{
e[x].push_back(y);
}
}
int ans=;
for(int i=;i<n;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i)==)
ans++;
}
printf("%d\n",ans);
} }

hdu 1150 Machine Schedule 最少点覆盖的更多相关文章

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

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

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

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

  3. hdu 1150 Machine Schedule&lpar;最小顶点覆盖&rpar;

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

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

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

  5. HDU——1150 Machine Schedule

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

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

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

  7. hdu 1150 Machine Schedule &lpar;二分匹配&rpar;

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

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

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

  9. HDU 1150 Machine Schedule &lpar;二分图最小点覆盖&rpar;

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

随机推荐

  1. 【目录】JUC集合框架目录

    JUC集合框架的目录整理如下: 1. [JUC]JUC集合框架综述 2. [JUC]JDK1.8源码分析之ConcurrentHashMap(一) 3. [JUC]JDK1.8源码分析之Concurr ...

  2. Vim Using

    1 2 set nu 3 set backup 4 set bg=light 5 " transform tab to space 6 set expandtab 7 " auto ...

  3. Android Textview实现文字颜色渐变效果

    最近做应用的时候遇到一个需求,一行文字的颜色需要一个渐变效果 如上所有 从左到有逐渐变化,自己写了一个demo实现上述效果 package com.huwei.example.test; import ...

  4. 手把手教你编译安装MariaDB

    MariaDB是什么? MariaDB是MySQL的一个分支,由于Oracle有可能对MySQL闭源,所以分离了出来(MySQL先后被Sun.Oracle收购). 但是除了作为一个Mysql的&quo ...

  5. 在linux中查询硬件相关信息

    1.查询cpu的相关 a.查询CPU的统计信息 使用命令:lscpu 得到的结果如下: Architecture: x86_64 CPU op-mode(s): -bit, -bit Byte Ord ...

  6. ios开发中经常用到的控件

    以下是按照使用频率对ios的控件进行罗列. 1.最常用的UI控件: UIButton (按钮).UILabel (文本标签).UITextField (文本输入框).UIImageView( 图片显示 ...

  7. Principal Data Scientist

    http://*.com/jobs/124781/principal-data-scientist-concur-technologies-inc?med=clc&re ...

  8. Hibernate学习0&period;Hibernate入门

    Hibernate是什么 面向java环境的对象/关系数据库映射工具. 1.开源的持久层框架. 2.ORM(Object/Relational Mapping)映射工具,建立面向对象的域模型和关系数据 ...

  9. 【FFT】专题总结

    学了若干天终于学(bei)会了传说中的法法塔 感觉也没那么难用嘛 fft快速傅里叶变换 在大表课件上写就是解决高精乘的工具 其实很有理有据 fft就是用复数的折半引理优化两个多项式相乘的高端东西 他能 ...

  10. nginx - conf&period;d vs sites-available

    自己理解: conf.d - 扩展配置文件,用户配置文件 sites-available - 配置 虚拟主机(nginx支持多个虚拟主机,sites-enabled(存放 软链接,指向sites-av ...