poj 1325 Machine Schedule 题解
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 14479 | Accepted: 6172 |
Description
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 will be terminated by a line containing a single zero.
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
0
Sample Output
3
Source
最小点集覆盖—— 用最少的点,覆盖所有边。
这里面,边指任务,点指机器模式。
这里面的特点是在任务执行顺序没有要求的条件下才可以使用最小点集覆盖。
这里具体还是使用匈牙利算法,找到最大匹配的边数——实际意义为找到匹配边的其中三个对应点,能够覆盖所有的任务。
/*
Problem:
OJ:
User:
Time:
Memory:
Length:
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#include<vector>
#include<list>
#include<map>
#define maxn 101
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
#define maxm 2016
#define mod 1000000007
//#define LOCAL
using namespace std;
int 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 n,m,k;
int mp[maxn][maxn];
int px[maxn],py[maxn];
int ans;
int cx[maxn],cy[maxn];
inline int path(int u)
{
cx[u]=;
F(i,,m){
if(mp[u][i]>&&!cy[i]){
cy[i]=;
if(!py[i]||path(py[i]))
{
px[u]=i;
py[i]=u;
return ;
}
}
}
return ;
}
inline void solve()
{
ans=;
M(px,);M(py,);
F(i,,n){
if(!px[i]){
M(cx,);M(cy,);
ans+=path(i);
}
}
return;
}
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
while(cin>>n)
{
if(n==) break;
cin>>m>>k;M(mp,);
F(i,,k){
int a,b,c;
cin>>a>>b>>c;
mp[b][c]=;
}
solve();
cout<<ans<<endl;
}
return ;
}
poj 1325 Machine Schedule 题解的更多相关文章
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- 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 最小点覆盖
题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...
- 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(最小点覆盖)
http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ...
- poj 1325 Machine Schedule 解题报告
题目链接:http://poj.org/problem?id=1325 题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1.每一个作业能运行在 A 的 ...
- 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机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
随机推荐
- 常用工具(Windows版本)
为原有版本修改为markdown后的更新,这个编辑器真心不错,只需要把原来喜欢的表格改成列表即可. 代码工具 代码管理工具 SourceTree:支持windows和mac跨平台使用的git图形化客户 ...
- Android-认识Service
Android-认识Service 学习自 郭霖的博客 https://developer.android.google.cn/reference/android/app/Service#WhatIs ...
- [USACO08NOV]Time Management
[USACO08NOV]Time Management 题目大意: 有\(n(n\le1000)\)个任务,同一时间只能进行一个任务.每个任务有一个进行时间\(t_i\)和一个截止时间\(s_i\), ...
- Nuget 下载过慢的解决办法
设置依赖项行为为忽略,文件冲突操作为忽略
- rsync使用ssh指定端口
增加以下参数: -e 'ssh -p 2222'
- Either, neither, both
http://speakspeak.com/resources/english-grammar-rules/various-grammar-rules/either-neither-both One ...
- 在阿里云里申请免费Https证书SSL
在阿里云控制台:安全(云盾)->证书服务->购买证书里(地址:https://common-buy.aliyun.com/?spm=5176.2020520163.cas.1.zTLyhO ...
- LOG EXPLORER ApexSQL Log
http://www.minisoft.cn/ https://www.apexsql.com/sql_tools_log.aspx
- 委托、Lambda表达式、事件系列03,从委托到Lamda表达式
在"委托.Lambda表达式.事件系列02,什么时候该用委托"一文中,使用委托让代码简洁了不少. namespace ConsoleApplication2 { internal ...
- Java Calendar,Date,DateFormat,TimeZone,Locale等时间相关内容的认知和使用(7) TimeZone
本章介绍TimeZone. TimeZone 简介 TimeZone 表示时区偏移量,也可以计算夏令时.在操作 Date, Calendar等表示日期/时间的对象时,经常会用到TimeZone:因为不 ...