题目链接

分析:

题意很难懂。

大体是这样的:给每个点的具体情况,1.容量 2。进入状态 3.出去状态。求最大流。

因为有很多点,所以如果一个点的出去状态满足另一个点的进入状态,则这两个点可以连一条边。容量为两者容量的较小值。

再建立一个超源、一个超汇。让超源与所有进入状态全为0或者不全为0但只包含0和2的点连边,同时让所有出去状态全部为1的与超汇连边。

然后求最大流.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue> using namespace std; const int maxn = ;
const int INF = (<<); int in[maxn][], cap[maxn][maxn], n, flow[maxn][maxn]; int EK(int s, int t) {
queue<int> q;
int p[maxn], a[maxn]; int f = ; memset(flow, , sizeof(flow)); while(true) {
memset(a, , sizeof(a));
a[s] = INF;
q.push(s);
while(!q.empty()) {
int u = q.front(); q.pop();
for(int v = ; v < n; v++) if(!a[v] && cap[u][v] > flow[u][v]) {
p[v] = u; q.push(v);
a[v] = min(a[u], cap[u][v]-flow[u][v]);
}
} if(a[t] == ) break;
for(int u=t; u != s; u = p[u]) {
flow[p[u]][u] += a[t];
flow[u][p[u]] -= a[t];
}
f += a[t];
}
return f;
} int main() {
int p; while(scanf("%d%d", &p, &n) == ) { memset(cap, , sizeof(cap)); for(int i=; i<*p+; i++) { //初始化超源,超汇
in[][i] = ;
in[n+][i] =;
} for(int i=; i<=n; i++) { //输入数据
for(int j=; j<*p+; j++) {
scanf("%d", &in[i][j]);
}
} n+=; //点数+2 for(int i=; i<n; i++) { //将可以连通的点,记录,算出每条边的容量
for(int j=; j<n; j++) {
if(i == j) continue; bool flag = true;
for(int k=; k<=p; k++) {
if( !((in[j][k] == ) || (in[i][k+p] == in[j][k])) ) {
flag = false;
}
}
if(flag && i == ) cap[i][j] = in[j][];
else if(flag && j == n-) cap[i][j] = in[i][];
else if(flag) cap[i][j] += min(in[i][], in[j][]);
}
} printf("%d ", EK(, n-)); //增广路算法 int cnt = ; //计数
for(int i=; i<n-; i++) {
for(int j=; j<n-; j++) {
if(flow[i][j] > ) cnt++;
}
}
printf("%d\n", cnt); for(int i=; i<n-; i++) { //输出
for(int j=; j<n-; j++) {
if(flow[i][j] > ) printf("%d %d %d\n", i, j, flow[i][j]);
}
}
} return ;
}

POJ3436 ACM Computer Factory(最大流)的更多相关文章

  1. POJ3436 ACM Computer Factory —— 最大流

    题目链接:https://vjudge.net/problem/POJ-3436 ACM Computer Factory Time Limit: 1000MS   Memory Limit: 655 ...

  2. poj-3436.ACM Computer Factory(最大流 + 多源多汇 + 结点容量 + 路径打印 + 流量统计)

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10940   Accepted:  ...

  3. POJ-3436 ACM Computer Factory 最大流 为何拆点

    题目链接:https://cn.vjudge.net/problem/POJ-3436 题意 懒得翻,找了个题意. 流水线上有N台机器装电脑,电脑有P个部件,每台机器有三个参数,产量,输入规格,输出规 ...

  4. POJ3436 ACM Computer Factory 【最大流】

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5412   Accepted: 1 ...

  5. poj3436 ACM Computer Factory, 最大流,输出路径

    POJ 3436 ACM Computer Factory 电脑公司生产电脑有N个机器.每一个机器单位时间产量为Qi. 电脑由P个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...

  6. POJ3436 ACM Computer Factory(最大流/Dinic)题解

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8944   Accepted: 3 ...

  7. POJ-3436 ACM Computer Factory(网络流EK)

    As you know, all the computers used for ACM contests must be identical, so the participants compete ...

  8. Poj 3436 ACM Computer Factory (最大流)

    题目链接: Poj 3436 ACM Computer Factory 题目描述: n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑? 解题 ...

  9. POJ-3436:ACM Computer Factory (Dinic最大流)

    题目链接:http://poj.org/problem?id=3436 解题心得: 题目真的是超级复杂,但解出来就是一个网络流,建图稍显复杂.其实提炼出来就是一个工厂n个加工机器,每个机器有一个效率w ...

随机推荐

  1. Android网络框架---OkHttp3

    1.添加依赖 compile 'com.squareup.okhttp3:okhttp:3.4.2' project Structure-->dependencied/搜索okhttp. com ...

  2. 关于 Head First SQL 中文版

    我想谈谈 我对于Head  First  SQL  中文版的一些看法 事实上关于我翻译的这个Head  First  SQL 中文版..我自觉得:的确翻译得非常烂.. 和翻译Head  First  ...

  3. 我的搜索优化记录(一):中文分词优化IK Analyzer

    搜索绝对不仅仅是搭起框架,跑出结果就完成的工作,之后分词.排序等等的优化才是重头戏. 先交代下背景:这个搜索是我一个人负责搭建并优化的项目,主要索引对象为歌曲.歌手MV等等. 使用技术:Lucene. ...

  4. vim note(4)

    :new 文件名.词尾 新文件. :e 文件名 打开文件. :w 文件名.txt 保存文件. :wq 保存并退出. :x 辍学.假设文件更改被保存 版权声明:本文博主原创文章,博客,未经同意不得转载.

  5. 各种div+css居中方式调整(转载)

    盘点8种CSS实现垂直居中水平居中的绝对定位居中技术 分类: 前端开发2013-09-11 21:06 24959人阅读 评论(3) 收藏 举报 绝对居中垂直居中水平居中CSS居中代码   目录(?) ...

  6. 《Android开发艺术探索》读书笔记 (7) 第7章 Android动画深入分析

    本节和<Android群英传>中的第七章Android动画机制与使用技巧有关系,建议先阅读该章的总结 第7章 Android动画深入分析 7.1 View动画 (1)android动画分为 ...

  7. Android短信的发送和接收监听

    /**发送与接收的广播**/ String SENT_SMS_ACTION = "SENT_SMS_ACTION"; String DELIVERED_SMS_ACTION = & ...

  8. python文档字符串

    #coding=utf-8 #文档字符串def d(i,j): """这个函数实现了一个乘法运算. 函数会返回一个乘法运算的结果.""" k ...

  9. css样式之背景图片

    1.css样式背景之使用图片来做为背景 example: <!DOCTYPE html> <html> <head> <meta http-equiv=&qu ...

  10. 免写前缀JS包--prefixfree.min.js--插件

    /** * StyleFix 1.0.3 & PrefixFree 1.0.7 * @author Lea Verou * MIT license */ (function(){functio ...