题目链接

分析:

题意很难懂。

大体是这样的:给每个点的具体情况,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. [PWA] 6. Hijacking response

    For example, if the url is not match to any API endpoint, we want to return 404 error message. So fi ...

  2. 浅析mysql 共享表空间与独享表空间以及他们之间的转化

        innodb这种引擎,与MYISAM引擎的区别很大.特别是它的数据存储格式等.对于innodb的数据结构,首先要解决两个概念性的问题: 共享表空间以及独占表空间.什么是共享表空间和独占表空间共 ...

  3. python瓦登尔湖词频统计

    #瓦登尔湖词频统计: import string path = 'D:/python3/Walden.txt' with open(path,'r',encoding= 'utf-8') as tex ...

  4. python增删改查

    ###增删改查 names = ["zhangding","wangxu","wudong","cheng"] #增na ...

  5. 9.14noip模拟试题

    中文题目名称 祖孙询问 比赛 数字 英文题目名称 tree mat num 可执行文件名 tree mat num 输入文件名 tree.in mat.in num.in 输出文件名 tree.out ...

  6. The following module was built either with optimizations enabled or witherout debug information

    出现这个问题的原因是这个程式有做版控,服务器上的版本比本机版本小 解决方式为:删除服务器上的版控或者本机版本改成与服务器一致即可

  7. session在登录中的使用

    package action.exam; import java.util.Map; import com.opensymphony.xwork2.ActionContext; import com. ...

  8. node.js的ejs模版引擎

    ejs版本是0.8.8,生成的views目录下面只有index.ejs and error.ejs,没有layout.ejs. D:\lianchuangfile\nodeDevelop\microb ...

  9. phonegap 2.8.1 toast

    目录结构如下: 以上三个用红色框勾出的地方是需要修改的文件夹. 首先:添加java代码. 在src目录下新建一个包裹:org.apache.cordova 在该包裹下新建类:ToastPlugin.j ...

  10. 关于java中Double类型的运算精度问题(转)

    Java Java double:浮点数:精确计算  public class Test{    public static void main(String args[]){        Syst ...