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

 
 
正解:二分图匹配
解题报告:
  今天考试T3,今天也就切了这道题了...
  考虑每个点相当于是一个矩阵里面的坐标,要么这一行被选,要么这一列被选,所以可以直接转成最小覆盖集模型。
  首先,把坐标含0的全部去掉,然后跑二分图最大匹配,由于最小覆盖等于最大匹配,可以直接得到答案。
  所以这道题就是一个最小点覆盖的裸题...
 
 
 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int MAXN = ;
const int MAXM = ;
int n,m,k,ecnt;
int first[MAXN],to[MAXM],next[MAXM],match[MAXN];
bool vis[MAXN];
int ans; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline bool dfs(int x){
if(vis[x]) return false;
vis[x]=;
for(int i=first[x];i;i=next[i]) {
int v=to[i]; if(vis[v]) continue;
if(!match[v] || dfs(match[v])) {
match[x]=v; match[v]=x;
return true;
}
}
return false;
} inline void work(){
while(scanf("%d",&n)!=EOF) {
if(n==) break;
m=getint(); k=getint();
int x,y; memset(first,,sizeof(first)); memset(match,,sizeof(match));
ecnt=;
for(int i=;i<=k;i++) {
x=getint(); x=getint(); y=getint();
if(x== || y==) { i--; k--; continue; }
y+=n;
next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y;
next[++ecnt]=first[y]; first[y]=ecnt; to[ecnt]=x;
}
ans=;
for(int i=;i<n;i++) {
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
printf("%d\n",ans);
}
} int main()
{
work();
return ;
}

POJ1325 Machine Schedule的更多相关文章

  1. POJ1325 Machine Schedule 【二分图最小顶点覆盖】

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11958   Accepted: 5094 ...

  2. POJ-1325 Machine Schedule,和3041有着异曲同工之妙,好题!

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K       Description As we all know, machine ...

  3. [poj1325] Machine Schedule (二分图最小点覆盖)

    传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...

  4. POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题

    POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...

  5. POJ1325 Machine Schedule(二分图最小点覆盖集)

    最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...

  6. Machine Schedule poj1325

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17454   Accepted: 7327 ...

  7. POJ 1325 Machine Schedule——S.B.S.

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

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

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

  9. Machine Schedule

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

随机推荐

  1. 第51课 C++对象模型分析(下)

    1. 单继承对象模型 (1)单一继承 [编程实验]继承对象模型初探 #include <iostream> using namespace std; class Demo { protec ...

  2. Hill密码

    希尔密码(Hill Password)是运用基本矩阵论原理的替换密码,由Lester S. Hill在1929年发明.每个字母当作26进制数字:A=, B=, C=... 一串字母当成n维向量,跟一个 ...

  3. 搭建一个Web应用

    因为EasyUI会涉及到与后台数据的交互,所以使用Spring MVC作为后台,搭建一个完整的Web环境 使用gradle作为构建工具 build.gradle group 'org.zln.lkd' ...

  4. 【转】【C#】序列化(Serialize)、反序列化(Deserialize)

    序列化又称串行化,是.NET运行时环境用来支持用户定义类型的流化的机制.其目的是以某种存储形成使自定义对象持久化,或者将这种对象从一个地方传输到另一个地方. .NET框架提供了两种串行化的方式: 1. ...

  5. win7(X64)系统下cuda7.5和VS2013的配置

    &1 安装 cuda7.5文件:链接:http://pan.baidu.com/s/1bU2zIQ 密码:nvyw &2 环境变量 注意:CUDA_PATH是安装好cuda7.5之后会 ...

  6. Angular权威指南学习笔记

    第一章.        初识Angular--Angular是MVW的Js框架. 第二章.        数据绑定--ViewModel中不仅可以含有变量,还可以还有事件.可以通过事件来控制变量的值改 ...

  7. bisController

    public class BisController : Controller { // // GET: /Bis/ protected string GetJson(object obj) { Is ...

  8. 亚博 Arduino智能小车实验报告

    亚博 Arduino智能小车实践报告 一.     程序安装准备 首先安装了Arduino板载USB转串口CH340驱动安装包, 若上述程序安装成功,则可以在我的电脑中找到相应的端口 本机端口号为CO ...

  9. Ubuntu安装uget和aria2下载工具

    Windows下的下载工具有迅雷,快车等.Ubuntu下也有强大的下载工具uget和aria2. 一.安装.uget和aria2都可以在“软件中心”中安装,但是版本太老啦,所以最好还是在终端中添加pp ...

  10. 解决jquery $符号的冲突

    今天做项目的时候,写了一个ajax提交的js函数,然后在js调试的时候,提示发现 $.ajax ,前面的$ 符号不见了,通过网上搜索找到了下面的解决方法 jQuery中需要用到$符号,如果其他js库也 ...