【图论】【二分图匹配】[POJ 1325]Machine Schedule
2015-07-28 15:57
447 查看
可以发现如果把一条边看作一个任务,那么连接的就是两台机器的模式的编号,那么问题就转化成了最小的点覆盖问题,那么注意特殊处理存在一个任务在任意一台机器中是0的情况,因为一开始大家都是0,那么如果存在一个0直接不考虑这个任务就行了。
[code]#include <cstdio> #include <cstring> #include <algorithm> //#include <conio.h> using namespace std; const int MAXN = 400; bool vis[MAXN+10]; int con[MAXN+10]; int endcnt; int n, m, k; struct node{ int v; node *next; }Edges[2000*2+10], *adj[MAXN+10], *ecnt=Edges; void addedge(int u, int v){ ++ecnt; ecnt->v = v; ecnt->next = adj[u]; adj[u] = ecnt; } bool dfs(int u){ for(node *p=adj[u];p;p=p->next){ if(!vis[p->v]){ vis[p->v] = true; if(con[p->v]==-1 || dfs(con[p->v])){ con[u] = p->v; con[p->v] = u; return true; } } } return false; } int work(){ int ret = 0; memset(con, -1, sizeof con); for(int i=1;i<endcnt;i++) if(con[i] == -1){ memset(vis, 0, sizeof vis); ret += dfs(i); } return ret; } bool read(){ int t1, t2, t3; scanf("%d", &n); if(!n) return false; scanf("%d%d", &m, &k); for(int i=0;i<k;i++){ scanf("%d%d%d", &t1, &t2, &t3); if(!t2) continue; if(!t3) continue; addedge(t2, t3+n); addedge(t3+n, t2); } endcnt=n; return true; } void prepare(){ memset(adj, 0, sizeof adj); ecnt=Edges; } int main(){ while(read()){ printf("%d\n", work()); prepare(); } return 0; }
相关文章推荐
- Hot_Topic_Recognition
- js生成缩略图后上传并利用canvas重绘
- 企业证书APP发布流程
- 关于Linux的透明大页详细介绍
- codeproject 的精彩文章----对我有用
- Algorithm——QuickSort
- 深入理解C#中的泛型(一)
- CNN之Caffe配置
- html部分标签学习
- windows使用jad反编译jar
- Android推送如何实现思路
- 0728作报告有感
- CSS不常见问题汇总
- iOS越狱包
- iOS 发布流程
- 11g新特性 -- Virtual Private Catalogs
- 七牛云存储文件上传与下载
- rsync同步服务安装配置及脚本使用
- apachebench 服务器并发测试
- HDU 1015 Safecracker