【Poj1325】Machine Schedule机器调度
Position:
List
Description
我们知道机器调度是计算机科学中一个非常经典的问题。调度问题有很多种,具体条件不同,问题就不同。现在我们要处理的是两个机器的调度问题。
有两个机器A和B。机器A有n种工作模式,我们称之为mode_0,mode_l,……,mode_n-1。同样,机器B有m种工作模式,我们称之为mode_0,mode_1,……,mode_m-1。初始时,两台机器的工作模式均为mode_0。现在有k个任务,每个工作都可以在两台机器中任意一台的特定的模式下被加工。例如,job0能在机器A的mode_3或机器B的mode_4下被加工,jobl能在机器A的mode_2或机器B的mode_4下被加工,等等。因此,对于任意的jobi,我们可以用三元组(i,x,y)来表示jobi在机器A的mode_x或机器B的mode_y下被加工。
显然,要完成所有工作,我们需要不时的改变机器的工作模式。但是,改变机器的工作状态就必须重启机器,这是需要代价的。你的任务是,合理的分配任务给适当的机器,使机器的重启次数尽量少。
Input
第一行三个整数n,m(n,m<=100),k(k<6000)。接下来的k行,每行三个整数i,x,y。
Output
只一行一个整数,表示最少的重启次数。
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
Sample Output
3
HINT
30%: n,m<30, k<100
100%: n,m<100,k<10000
Solution
二分图匹配直接上(Dinic||匈牙利)
Analysis:Konig 定理:最大匹配数 = 最小点覆盖数
注意开始机器是开着的,两边都为零,所以连的边都可以去掉
可恶的样例,居然没0,然后rank10->rank22,80分啊!
Code
// <machine.cpp> - Fri Sep 23 08:09:06 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=210;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
int n,match[MAXN];
vector<int>b[MAXN];bool f[MAXN];
inline void add(int v,int u){
if(!(v&&u))return;//这句话顶80分,坑~
b[u].push_back(v+n);b[v+n].push_back(u);
}
inline bool dfs(register int x){
if(f[x])return 0;
int num=b[x].size();f[x]=true;
for(int i=0;i<num;i++){
int nex=b[x][i];
if(match[nex]==-1||dfs(match[nex])){
match[x]=nex;match[nex]=x;return 1;
}
}
return 0;
}
int main()
{
freopen("machine.in","r",stdin);
freopen("machine.out","w",stdout);
while(n=gi(),n){
int ans=gi(),k=gi();
for(int i=0;i<=ans+n;i++)b[i].clear();
for(int i=1;i<=k;i++)ans=gi(),add(gi(),gi());
for(int i=0;i<MAXN;i++)match[i]=-1;ans=0;
for(int i=0;i<n;i++)
if(match[i]==-1){
memset(f,0,sizeof(f));
if(dfs(i))ans++;
}
printf("%d\n",ans);
}
return 0;
}
【Poj1325】Machine Schedule机器调度的更多相关文章
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11958 Accepted: 5094 ...
- POJ-1325 Machine Schedule,和3041有着异曲同工之妙,好题!
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Description As we all know, machine ...
- [poj1325] Machine Schedule (二分图最小点覆盖)
传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...
- POJ1325 Machine Schedule
Description As we all know, machine scheduling is a very classical problem in computer science and h ...
- POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题
POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...
- POJ1325 Machine Schedule(二分图最小点覆盖集)
最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...
- Machine Schedule poj1325
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17454 Accepted: 7327 ...
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
随机推荐
- RESTful API设计的简单例子
代码承接简单服务器,修改 app.js const koa = require('koa'), app = new koa(), Router = require('koa-router'), rou ...
- PMP 学习心得
前两天刚考完 PMP,松了一口气,终于考完了,虽然心里有点慌,不知道自己会不会过.学习 PMP 这三个月还是很充实的.不断的看视频,做题目,功夫不负有心人,也算是学到了一些东西.至少知道了一个项目的启 ...
- spring boot+mybatis+mysql增删改查分页
server: port: servlet: context-path: /springBootMybatis spring: datasource: name: test url: jdbc:mys ...
- JQuery 的toggle() 方法如何使用?
JQuery中的toggle()方法,相当于点一个元素时,重复循环两个函数,而这两个函数可以作为toggle()函数的两个参数传进去,当第一次点击的时候会执行前面的参数,而第二次点击时执行的是后面的参 ...
- 40条常见的移动端Web页面问题解决方案
1.安卓浏览器看背景图片,有些设备会模糊.想让图片在手机里显示更为清晰,必须使用2x的背景图来代替img标签(一般情况都是用2倍).例如一个div的宽高是100100,背景图必须得200200,然后b ...
- 12Cookie、Session
12Cookie.Session-2018/07/24 1.保存会话数据 cookie客户端技术,把每个用户的数据以cookie的形式写给用户各自的浏览器 HttpSession服务端技术,服务器运行 ...
- Python习题之列表排序,4种方法
def sort_list_method_1(a): return sorted(a) print(sort_list_method_1([1, 4, 2])) def sort_list_metho ...
- 线程 synchronized锁机制
脏读 一个常见的概念.在多线程中,难免会出现在多个线程中对同一个对象的实例变量进行并发访问的情况,如果不做正确的同步处理,那么产生的后果就是"脏读",也就是取到的数据其实是被更改过 ...
- 【03】全局 CSS 样式
全局 CSS 样式 设置全局 CSS 样式:基本的 HTML 元素均可以通过 class 设置样式并得到增强效果:还有先进的栅格系统. 概览 深入了解 Bootstrap 底层结构的关键部分,包括我们 ...
- 数据库中间件MyCat学习总结(2)——MyCat-Web原理介绍
Mycat是一个分库分表的基于java开发的数据库中间件,使用过程中需要有一个监控系统,mycat-web应运而生.mycat-web是一个使用SpringMVC + Mybatis的监控平台,使用常 ...