Poj(1325),最小点覆盖
题目链接:http://poj.org/problem?id=1325
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 14216 | Accepted: 6075 | 
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
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
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
#include <stdio.h>
#include <string.h> int n,m,k;
bool maps[][];
int match[];
bool use[]; bool DFS(int u)
{
for(int i=;i<m;i++)
{
if(!use[i]&&maps[u][i])
{
use[i] = true;
if(match[i]==-||DFS(match[i]))
{
match[i] = u;
return true;
}
}
}
return false;
} int main()
{
while(scanf("%d",&n))
{
if(n==) break;
scanf("%d%d",&m,&k);
memset(maps,false,sizeof(maps));
memset(match,-,sizeof(match)); for(int i=;i<k;i++)
{
int t,a,b;
scanf("%d%d%d",&t,&a,&b);
maps[a][b] = true;
}
/*for(int i=0;i<m;i++)
{
if(maps[0][i])
maps[0][i] = false;
}
for(int i=0;i<n;i++)
{
if(maps[i][0])
maps[i][0] = false;
}*/
int num = ;
for(int i=;i<n;i++)
{
memset(use,false,sizeof(use));
if(DFS(i))
num++;
}
printf("%d\n",num);
}
return ;
}
Poj(1325),最小点覆盖的更多相关文章
- POJ 2226 最小点覆盖(经典建图)
		Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8881 Accepted: 3300 Desc ... 
- POJ 2446 最小点覆盖
		Chessboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14787 Accepted: 4607 Descr ... 
- poj  3041  最小点覆盖=最大匹配
		#include<stdio.h> #include<string.h> #define N 510 int map[N][N],n,mark[N],link[N]; in ... 
- 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(最小点覆盖)
		http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ... 
- 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 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)
		题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ... 
- poj 3041 Asteroids(最小点覆盖)
		http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ... 
随机推荐
- PostgreSQL Loadbalance Analysis CPU
			Before we can even begin to decide on a processor count, we need a baseline. With a working PostgreS ... 
- SQL order 排序
			select * from emp; 
- WinForm利用 WinApi实现 淡入淡出 弹出 效果 仿QQ消息
			消息框: using System.Runtime.InteropServices; namespace Windows_API_实现屏幕右下角_消息框_ { public partial class ... 
- jvm排查工具
			jps jps -mvl --查看java的ps进程. jstack 打印一个线程堆栈信息 top -H -p pid1 -> 得到占用资源大的pid2 jstack pid1 | grep & ... 
- 【sinatra】设置默认的端口
			加入 set :port, 8888 #默认4567 
- MYSQL 、Oracle、SQLServer 数据库中时间的格式化输出
			在MYSQL 中格式化输出 date_forma t(date,'yyyyMMddHHmmss') Oracle 中格式化输出 to_char(time ,'yyyyMMddHHmmss') SQL ... 
- SQL2005中的事务与锁定(一) - 转载
			----------------------------------------------------------------------- -- Author : HappyFlyStone -- ... 
- 最长上升子序列O(nlogn)算法详解
			最长上升子序列 时间限制: 10 Sec 内存限制:128 MB 题目描述 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.我们想知道此时最长上升子 ... 
- android小功能:checkbox使用自己的背景点击切换背景
			xiazai_checkbox.xml <?xml version="1.0" encoding="utf-8"?> <selector xm ... 
- Qt可执行程序写入版本信息
			[1]新建Qt工程 1.1 具体新建步骤不赘述. 1.2 新建工程后文件目录如下: 1.3 留意对比一下你的代码目录,可以发现我的文件目录中多了一个rc类型的资源文件.那么,它也就是关键点. 1.4 ... 
