题目链接:

  Poj 3436 ACM Computer Factory

题目描述:

  n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑?

解题思路:

  因为需要输出流水线要经过的工厂路径,如果要用电脑状态当做节点的话,就GG了。所以建图的时候要把工厂当做节点。对于节点i,能生产si电脑的节点可以进入节点i,能转化ei电脑的节点可以由i节点进入。要注意对于每一个节点要进行拆点,防止流量发生错误。

 #include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f3f;
struct node
{
int x, s[], e[];
} mach[maxn];
struct node1
{
int s, e, x;
} path[maxn*maxn];
int maps[maxn*][maxn*], Maps[maxn*][maxn*];
int Layer[maxn*], p, n, num; void buildmaps (int s, int e)
{
for (int i=s; i<=e; i++)
{
int j, k;
for (int j=s; j<=e; j++)
{
if (i == j)
continue;
for (k=; k<p; k++)
{
if (mach[i].e[k]== || mach[j].s[k]==)
continue;
if (mach[i].e[k] != mach[j].s[k])
break;
}
if (k == p)
{
if (i > )
Maps[i+n][j] = mach[i].x;
else
Maps[i][j] = mach[i].x;
}
}
} for (int i=; i<=num; i++)
for (int j=; j<=num; j++)
maps[i][j] = Maps[i][j];
} bool CountLayer (int s, int e)
{
queue <int> Q;
memset (Layer, , sizeof(Layer));
Layer[s] = ;
Q.push (s); while (!Q.empty ())
{ int u = Q.front();
Q.pop(); for (int i=; i<=num; i++)
if (!Layer[i] && maps[u][i])
{
Layer[i] = Layer[u] + ;
Q.push (i);
if (i == e)
return true;
}
}
return false;
} int Dfs (int u, int e, int maxflow)
{
if (u == e)
return maxflow; int uflow = ;
for (int i=; i<=num; i++)
{
if (maps[u][i] && Layer[i]==Layer[u]+)
{
int flow = min(maps[u][i], maxflow - uflow);
flow = Dfs (i, e, flow); uflow += flow;
maps[u][i] -= flow;
maps[i][u] += flow;
if (uflow == maxflow)
break;
}
} if (uflow == )
Layer[u] = ; return uflow;
} int Dinic (int s, int e)
{
int maxflow = ; while (CountLayer(s, e))
maxflow += Dfs(s, e, INF); return maxflow;
} int main ()
{
while (scanf ("%d %d", &p, &n) != EOF)
{
memset (mach, , sizeof(mach));
memset (Maps, , sizeof(Maps));
mach[].x = INF;
for (int i=; i<p; i++)
{
mach[].s[i] = INF;
mach[].e[i] = INF;
mach[].s[i] = ;
} for (int i=; i<n+; i++)
{
scanf ("%d", &mach[i].x);
for (int j=; j<p; j++)
scanf ("%d", &mach[i].s[j]);
for (int j=; j<p; j++)
scanf ("%d", &mach[i].e[j]);
Maps[i][i+n] = mach[i].x;//拆点
} int ans, res;
res = ;
num = n + n + ; buildmaps (, n+);
ans = Dinic (, ); for (int i=; i<num; i++)
{
for (int j=; j<num; j++)
{ if (i == j+n || j==i+n)
continue; if (Maps[i][j] - maps[i][j] > )
{
path[res].x = Maps[i][j] - maps[i][j];
path[res].s = (i - ) % n + ;
path[res++].e = (j - ) % n + ;
} }
} printf ("%d %d\n", ans, res);
for (int i=; i<res; i++)
printf ("%d %d %d\n", path[i].s, path[i].e, path[i].x); }
return ;
}

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

  1. POJ 3436 ACM Computer Factory 最大流,拆点 难度:1

    题目 http://poj.org/problem?id=3436 题意 有一条生产线,生产的产品共有p个(p<=10)零件,生产线上共有n台(n<=50)机器,每台机器可以每小时加工Qi ...

  2. poj 3436 ACM Computer Factory 最大流+记录路径

    题目 题意: 每一个机器有一个物品最大工作数量,还有一个对什么物品进行加工,加工后的物品是什么样.给你无限多个初始都是000....的机器,你需要找出来经过这些机器操作后最多有多少成功的机器(111. ...

  3. POJ 3436 ACM Computer Factory (网络流,最大流)

    POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...

  4. POJ - 3436 ACM Computer Factory 网络流

    POJ-3436:http://poj.org/problem?id=3436 题意 组配计算机,每个机器的能力为x,只能处理一定条件的计算机,能输出特定的计算机配置.进去的要求有1,进来的计算机这个 ...

  5. POJ - 3436 ACM Computer Factory(最大流)

    https://vjudge.net/problem/POJ-3436 题目描述:  正如你所知道的,ACM 竞赛中所有竞赛队伍使用的计算机必须是相同的,以保证参赛者在公平的环境下竞争.这就是所有这些 ...

  6. POJ 3436 ACM Computer Factory(最大流+路径输出)

    http://poj.org/problem?id=3436 题意: 每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了.计算机的生产过程通过N台不同的机器来完成,每台机器用它的性 ...

  7. POJ 3436 ACM Computer Factory (拆点+输出解)

    [题意]每台计算机由P个零件组成,工厂里有n台机器,每台机器针对P个零件有不同的输入输出规格,现在给出每台机器每小时的产量,问如何建立流水线(连接各机器)使得每小时生产的计算机最多. 网络流的建图真的 ...

  8. POJ 3436 ACM Computer Factory

    题意:   为了追求ACM比赛的公平性,所有用作ACM比赛的电脑性能是一样的,而ACM董事会专门有一条生产线来生产这样的电脑,随着比赛规模的越来越大,生产线的生产能力不能满足需要,所以说ACM董事会想 ...

  9. kuangbin专题专题十一 网络流 POJ 3436 ACM Computer Factory

    题目链接:https://vjudge.net/problem/POJ-3436 Sample input 1 3 4 15 0 0 0 0 1 0 10 0 0 0 0 1 1 30 0 1 2 1 ...

随机推荐

  1. 从Java代码到字节码

    http://www.importnew.com/13107.html http://blog.csdn.net/dc_726/article/details/7944154/ http://www. ...

  2. java.net.URISyntaxException的解决办法

    java.net.URISyntaxException的解决办法 近日在用HttpClient访问抓取汇率时,为了省力,直接采用 String url = "http://api.liqwe ...

  3. jsoup 提取 html 中的所有链接、图片和媒体

    原文:http://www.open-open.com/code/view/1420729333515 package org.jsoup.examples; import org.jsoup.Jso ...

  4. weblogic集群的资料

    博客分类: weblogic 其实网上关于weblogic集群的资料非常多[大部分都是从创建新的domain开始,我这篇先介绍怎么样把原本普通的domain改造为集群环境],如果觉得不够,可以啃web ...

  5. c++之函数对象、bind函数

    函数对象实质上是一个实现了operator()--括号操作符--的类. class Add { public: int operator()(int a, int b) { return a + b; ...

  6. Mac 使用smb协议连接FTPserver

    在Mac中,能够通过smb协议作为client连接到server,比如一个FTPserver,然后获取上面的共享文件. 方法: 1.在Finder菜单中点击前往 -- 连接server. 也能够Com ...

  7. 基于docker容器搭建fastdfs分布式文件系统

    本次环境的搭建参考了 https://blog.csdn.net/qq_43455410/article/details/84797814, 感谢博主. 主要流程如下: 1. 下载fastdfs镜像 ...

  8. c语言实现输出一个数的每一位

    比方输入1234.在屏幕上打印出1 2 3 4 代码展示: 方法一: #define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #includ ...

  9. How to Use SFTP ?

    Usage Build a SFTP session with your linux like server, e.g, by the tool "Xshell" or any y ...

  10. Python标准库:内置函数complex([real[, imag]])

    本函数能够使用參数real + imag*j方式创建一个复数.也能够转换一个字符串的数字为复数:或者转换一个数字为复数.假设第一个參数是字符串,第二个參数不用填写.会解释这个字符串且返回复数.只是,第 ...