poj 1325 Machine Schedule 最小点覆盖
题目链接:http://poj.org/problem?id=1325
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.
题目描述:现在有两台机器A和B,A机器有n种模式(0~n-1),B机器有m种模式(0~m-1),目前AB机器都处于模式0。给出k个工作,每个工作要么使机器A改变模式为i,要么使机器B改变模式为j。机器每次改变模式都需要重启一次,问k个工作完成之后,最少的重启次数。
算法分析:首先知道这是一个二分图。
给出这样一组数据:k=n=m=3
工作1可以改变A为1,改变B为2;工作2改变A为1,改变B为1;工作3改变A为1,改变B为0。
那么我们只需要一次重启就可以了:把A从0改变为1。
于是就想到了这道题可以用最小点覆盖来做。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+; int n,m,k;
int g[maxn][maxn],linker[maxn];
int vis[maxn]; int dfs(int u)
{
for (int v= ;v<m ;v++) if (g[u][v])
{
if (!vis[v])
{
vis[v]=;
if (linker[v]==- || dfs(linker[v]))
{
linker[v]=u;
return ;
}
}
}
return ;
} int hungary()
{
int ans=;
for (int i= ;i<n ;i++)
{
memset(vis,,sizeof(vis));
if (dfs(i)) ans++;
}
return ans;
} int main()
{
while (scanf("%d",&n)!=EOF && n)
{
scanf("%d%d",&m,&k);
memset(g,,sizeof(g));
memset(linker,-,sizeof(linker));
g[][]=;
int j,a,b;
while (k--)
{
scanf("%d%d%d",&j,&a,&b);
g[a][b]=;
}
printf("%d\n",hungary());
}
return ;
}
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 ...
- 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 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
- POJ 1325 Machine Schedule(zoj 1364) 最小覆盖数
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=364 http://poj.org/problem?id=1325 题目大意: ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- poj 1325 Machine Schedule
Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java class name ...
- poj 1325 Machine Schedule 题解
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14479 Accepted: 6172 ...
- poj 1325 Machine Schedule 解题报告
题目链接:http://poj.org/problem?id=1325 题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1.每一个作业能运行在 A 的 ...
随机推荐
- android任意view爆炸效果--第三方开源--ExplosionField
犹如天女散花一样,爆炸散列,比较有趣.Android ExplosionField在github上的项目主页是:https://github.com/tyrantgit/ExplosionField ...
- android属性
一.布局 1.android:layout_gravity和android:gravity的区别 android:gravity 对齐方式,它是相对于控件本身对齐:android:layout_gra ...
- python网络画图——networkX
networkX tutorial 绘制基本网络图 用matplotlib绘制网络图 基本流程: 1. 导入networkx,matplotlib包 2. 建立网络 3. 绘制网络 nx.draw() ...
- Python核心编程--学习笔记--2--Python起步(上)
本章是对Python的主要特性做一个快速介绍. 1 介绍 交互执行时,解释器有两种提示符: 主提示符(>>>):解释器在等待输入下一个语句: 次提示符(...):解释器在等待输入当前 ...
- .NET开源工作流RoadFlow-流程设计-流程属性设置
打开流程设计器点击新建流程后会弹出新流程属性设置框,属性设置包括基本信息,数据连接和标识字段三项设置. 1.基本信息 流程ID:系统自动给每个流程分配的一个唯一ID. 流程名称:给您的新流程取一个名称 ...
- Python sequence (序列)
序列简介 sequence 是一组有序元素的组合 序列可以是多个元素,也可以一个元素都没有 序列有2种:tuple(定值表).List(表) D:\python\Python_Day>pytho ...
- Linux下使用Magent+Memcached缓存服务器集群部署
1.编译安装libevent cd /root/soft_hhf/ wget http://cloud.github.com/downloads/libevent/libevent/libeven ...
- jdbc 连接 oracle rac
jdbc 连接 oracle rac 的连接串如下: jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192. ...
- 【TOP10 APP】这些应用成了AppCan千人大会的焦点
如何评价一款APP的好坏?首先,实用性.一款好的APP,首先要能为用户所用.然后是稳定流畅.闪退.卡顿,这样的APP用起来让人抓狂.再一个,界面美观.视觉主观性,在很大程度上会影响使用情况,毕竟没有人 ...
- 九度oj 1541 二叉树
原题链接:http://ac.jobdu.com/problem.php?pid=1541 简答题如下: #include<algorithm> #include<iostream& ...