Machine Schedule
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 13731   Accepted: 5873

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

Source

——————————————我是分割线————————————————————————————————
一道图论水题。
二分图最小覆盖,匈牙利算法。
首先构造二分图,各机器上的模式作为点,A机器为左部,B机器为右部。
把同一任务需要的模式之间连点。
之后只需用匈牙利算法计算,dfs增广求最小覆盖。
又因为二分图最小覆盖与最大匹配在数值上相等,只需求最大匹配即可。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
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 nx,ny,ans=;
bool map[][];
bool ex[],ey[];
int cx[],cy[];
void change();
int dfs(int);
int main()
{
std::ios::sync_with_stdio(false);
while(cin>>n)
{
if(n==) break;
cin>>m>>k;
memset(map,false,sizeof(map));
for(int i=;i<k;i++)
{
int a,b,c;
cin>>a>>b>>c;
map[b][c]=true;
}
change();
cout<<ans<<endl;
}
return ;
}
void change()
{
ans=;
int a,b,c;
memset(cx,,sizeof(cx));memset(cy,,sizeof(cy));
for(int i=;i<=n;i++)
{
if(!cx[i])
{
memset(ex,false,sizeof(ex));memset(ey,false,sizeof(ey));
ans+=dfs(i);
}
}
return;
}
int dfs(int u)
{
int a,b,c;
ex[u]=true;
int v;
for(v=;v<=m;v++)
{
if((map[u][v]==true)&&(ey[v]==false))
{
ey[v]=true;
if(!cy[v]||dfs(cy[v]))
{
cx[u]=v;cy[v]=u;
return ;
}
}
}
return ;
}

POJ 1325

POJ 1325 Machine Schedule——S.B.S.的更多相关文章

  1. poj 1325 Machine Schedule 二分匹配,可以用最大流来做

    题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...

  2. poj 1325 Machine Schedule 题解

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14479   Accepted: 6172 ...

  3. HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)

    Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...

  4. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  5. poj 1325 Machine Schedule

    Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u   Java class name ...

  6. POJ 1325 Machine Schedule(最小点覆盖)

    http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ...

  7. poj 1325 Machine Schedule 解题报告

    题目链接:http://poj.org/problem?id=1325 题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1.每一个作业能运行在 A 的 ...

  8. POJ 1325 Machine Schedule(zoj 1364) 最小覆盖数

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=364 http://poj.org/problem?id=1325 题目大意: ...

  9. POJ - 1325 Machine Schedule 二分图 最小点覆盖

    题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...

随机推荐

  1. healthMonitoring与运行状况监视

    配置针对应用程序的运行状况监视的一个服务 配置节内容比以往的较为复杂,如下 <healthMonitoring Enabled="true|false" heartbeatI ...

  2. MSSQL数据库的一些基础知识

    转几个关于MSSQL数据库基础的文章: sql server系统表详细说明 SQL Server中系统数据库介绍 SQL Server中的角色(服务器级别和数据库级别角色)

  3. 对hashmap,hashset,hashtable的理解

    1.首先先理一下java的集合关系,Collection和Map接口是所有集合接口的根结点,其他集合都直接或者间接的实现了他们中的一个:collection下有:list(元素可重复)和set(不可重 ...

  4. spring面试题(2)

    f-sp-1. Spring的aop你怎样实现? 用动态代理和cglib实现,有接口的用动态代理,无接口的用cglib f-sp-2. Spring在SSH起什么作用 整合作用 f-sp-3. Spr ...

  5. 【JAVA并发编程实战】5、构建高效且可伸缩的结果缓存

    首先创建一个借口,用来表示耗费资源的计算 package cn.xf.cp.ch05; public interface Computable<A, V> { V compute(A ar ...

  6. js中的位运算

    按位运算符是把操作数看作一系列单独的位,而不是一个数字值.所以在这之前,不得不提到什么是"位": 数值或字符在内存内都是被存储为0和 1的序列,每个0和1被称之为1个位,比如说10 ...

  7. 微信平台ASPX高级定制开发(一):如何使用C#建立响应微信接入和自动回复的代码

    微信平台不解释了,如果不了解的百度一下下,如果不会用微信,请自宫,光盘重启电脑,打开CMD输入Format C:.网上有很多针对企业级的高级定制ASPX开发,写得草草了事,很多男人干事都草草了事,这可 ...

  8. iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)

    在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...

  9. shareSDK实现分享操作时只显示英文字体

    今天用shareSDK实现分享操作时,突然发现分享视图只显示英文字体,而之前是显示中文的,以下是自己找到的解决方法: ,首先,找到shareSDk里的“ShareSDKUI_Localizable.s ...

  10. 在Linux环境下,将Solr部署到tomcat7中,导入Mysql数据库数据, 定时更新索引

    什么是solr solr是基于Lucene的全文搜索服务器,对Lucene进行了扩展优化. 准备工作 首先,去下载以下软件包: JDK8:jdk-8u60-linux-x64.tar.gz TOMCA ...