POJ1325
来源:互联网 发布:跟兄弟连学php.pdf下载 编辑:程序博客网 时间:2024/06/10 17:55
Problem : Machine Schedule
Description : 有A和B两种类型的机器,现在有一些工作,它可以在A和B中的任何一种机器中工作,然而,机器的开启是需要代价的,因此A中的第0个机器和B中的第0个机器一开始就是开着的,现在问你至少需要开启多少台机器才能使得所有的工作都被完成。
Solution : 二分图的最小点覆盖,点就是AB中的机器,而边就是一个工作在AB机器中的使用,于是这个最小点覆盖的意义就是用最少机器来使得所有的工作都能在机器中完成,建图完毕。但是这个题目要注意的是,机器0始终是开着的。那么如果边集中有0这个端点,那么我们就要去掉,因为这个工作不需要开启新的机器了,它在0机器上完成工作就可以了。如果对最小点覆盖不清楚可以参考下面的引用。
最小点覆盖的含义
Code(C++) :
#include <stdio.h>#include <string.h>#include <iostream>#include <string>#include <vector>using namespace std;const int F=1000+5;int n,m,k;vector<int> edge[F];bool used[F];int belong[F];bool dfs(int s){ for(int i=0;i<edge[s].size();i++){ int end=edge[s].at(i); if(used[end]) continue; used[end]=true; if(belong[end]==-1||dfs(belong[end])){ belong[end]=s; return true; } } return false;}int main(){ //freopen("in.data","r",stdin); while(scanf("%d",&n),n){ scanf("%d%d",&m,&k); int x,y; for(int i=0;i<F;i++) edge[i].clear(); memset(belong,-1,sizeof(belong)); for(int i=0;i<k;i++){ scanf("%*d%d%d",&x,&y); if(x*y) edge[x].push_back(y); } int sum=0; for(int i=1;i<n;i++){ memset(used,false,sizeof(used)); if(dfs(i)) ++sum; } printf("%d\n",sum); } return 0;}
0 0
- poj1325
- poj1325
- poj1325
- poj1325
- poj1325
- POJ1325
- poj1325最小点覆盖
- poj1325 - Machine Schedule
- poj1325 Machine Schedule
- poj1325(最小顶点覆盖)
- POJ1325 Machine Schedule
- poj1325 Machine Schedule
- poj1325最小顶点覆盖
- 【POJ1325】机器调度
- poj1325 2010.2.21
- Poj1325 Machine Schedule
- poj1325 machine schedule
- poj1325 air raid
- GIT使用
- opencv之边缘检测
- CI框架中浏览量(点击次数)
- Power of Two
- HDU Problem - 5363 Key Set 【快速幂】
- POJ1325
- 关于Cache-Control: no-cache和no-store
- linux中设置环境变量和gcc/g++的include路径
- 利用docker-compose和docker-swarm搭建ELK环境
- android学习笔记之运动事件MotionEvent
- WWW-万维网详解
- MyEclipse——快捷键的使用
- 进阶项目1-递归函数.立方和累加
- hadoop map 与reduce 的流程