题意:有一个ACM工厂会生产一些电脑,在这个工厂里面有一些生产线,分别生产不同的零件,不过他们生产的电脑可能是一体机,所以只能一些零件加工后别的生产线才可以继续加工,比如产品A在生产线1号加工后继续前往生产线2号继续加工,直到成为完全产品。输入 P 意思是这个电脑需要P个零件,N表示有N个生产线,每个生产线都有最大加工量,并且需要什么零件和输出的是什么零件,0表示没有这个零件,1表示有这个零件,2表示有没有都可以。
样例说明:
3 4
1号: 15  
0 0 0
  -->  
0 1 0

2号: 10  
0 0 0
  -->  
0 1 1

3号: 30  
0 1 2
  -->  
1 1 1

4号: 3   
0 2 1
  -->  
1 1 1

1号生产线需要0 0 0这样的零件(这样的零件也就是无限制零件,源点),它可以把零件加工成 0 1 0 这个样子,然后 3 号生产线可以接受这种零件,并且加工成 1 1 1 也就是成品,到这样也就加工成功了,因为1号生产线每次可以加工 15 个零件,所以1->3的加工量就是 15,同理 2->3的加工量是 10,所以结果是 25。


分析:很明显的网络流题目,感觉难点应该在题目阅读和建图上.....可以用0当做源点 N+1当做汇点,然后每两点都进行匹配一些,看看是否可以连接,路径的权值为出点的生产能力。


注意:因为每个生产线的生产能力有限,所以需要拆点,防止超出他的生产能力,比如下图如果不拆点结果就会使20,实际上是10

还有一定一定要注意的输入输出没有 


Sample output 1” “



Sample output 1


”!!!!就是这个坑我错了好多次


/**************************分割线**************分割线**************************************/

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std; const int MAXN = ;
const int oo = 1e9+; int G[MAXN][MAXN], layer[MAXN], G1[MAXN][MAXN];
int P, N;///需要P个零件,N条生产线
///表示生产线,需要的零件in,输出的零件out,最大生产值Flow
struct node{int in[MAXN], out[MAXN], Flow;}a[MAXN]; void InIt()
{
    memset(G, false, sizeof(G));
    memset(G1, false, sizeof(G1));     for(int i=; i<=P; i++)
    {
        a[].out[i] = ;
        a[].in[i] = ;
        a[N+].in[i] = ;
        a[N+].out[i] = ;
    }
    a[].Flow = oo;
    a[N+].Flow = oo;
}
bool canLink(node n1, node n2)
{///n1输出的零件是否是n2需要的
    for(int i=; i<=P; i++)
    {
        if(n1.out[i] != n2.in[i] && n2.in[i] != )
            return false;
    }     return true;
}
bool bfs(int start, int End)
{
    int used[MAXN] = {};
    queue<int> Q;Q.push(start);
    memset(layer, -, sizeof(layer));
    used[start] = true, layer[start] = ;     while(Q.size())
    {
        int u = Q.front();Q.pop();         if(u == End)return true;         for(int i=; i<=End; i++)
        {
            if(G[u][i] && !used[i])
            {
                used[i] = true;
                layer[i] = layer[u] + ;
                Q.push(i);
            }
        }
    }     return false;
}
int dfs(int u, int MaxFlow, int End)
{
    if(u == End)return MaxFlow;     int uFlow = ;     for(int i=; i<=End; i++)
    {
        if(layer[u]+==layer[i] && G[u][i])
        {
            int flow = min(MaxFlow-uFlow, G[u][i]);
            flow = dfs(i, flow, End);             G[u][i] -= flow;
            G[i][u] += flow;
            uFlow += flow;             if(uFlow == MaxFlow)
                break;
        }
    }     return uFlow;
}
int dinic(int start, int End)
{
    int MaxFlow = ;     while(bfs(start, End) == true)
        MaxFlow += dfs(start, oo, End);     return MaxFlow;
} int main()
{
    while(scanf("%d%d", &P, &N) != EOF)
    {
        int i, j;         InIt();         for(i=; i<=N+; i++)
        {
            scanf("%d", &a[i].Flow);
            for(j=; j<=P; j++)
                scanf("%d", &a[i].in[j]);
            for(j=; j<=P; j++)
                scanf("%d", &a[i].out[j]);
        }         N+=;         for(i=; i<=N; i++)
        for(j=; j<=N; j++)
        {
            if(i == j)
            {
                G1[i][j+N] = G[i][j+N] = a[i].Flow;
            }
            else if(i!=j && canLink(a[i], a[j]) == true)
            {
                G1[i+N][j] = G[i+N][j] = a[i].Flow;
            }
        }         int MaxFlow = dinic(, N*);
        int k=, x[MAXN], y[MAXN], flow[MAXN];         for(i=; i<N; i++)
        for(j=; j<N; j++)
        {
            if(G[i+N][j] < G1[i+N][j])
            {
                x[k] = i;
                y[k] = j;
                flow[k++] = G1[i+N][j] - G[i+N][j];
            }
        }         printf("%d %d\n", MaxFlow, k);
        for(i=; i<k; i++)
            printf("%d %d %d\n", x[i]-, y[i]-, flow[i]);
    }     return ;
}
/**
输入 3 5
10  0 0 0  0 1 0
10  0 0 0  0 1 0
10  0 1 0  0 1 1
10  0 1 1  1 1 1
10  0 1 1  1 1 1 输出 10 2
1 3 10
3 4 10 **/

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

  1. A - ACM Computer Factory POJ - 3436 网络流

    A - ACM Computer Factory POJ - 3436 As you know, all the computers used for ACM contests must be ide ...

  2. ACM Computer Factory - poj 3436 (最大流)

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5949   Accepted: 2053   Special Judge ...

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

    链接: http://poj.org/problem?id=3436 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82835#probl ...

  4. ACM Computer Factory POJ - 3436 网络流拆点+路径还原

    http://poj.org/problem?id=3436 每台电脑有$p$个组成部分,有$n$个工厂加工电脑. 每个工厂对于进入工厂的半成品的每个组成部分都有要求,由$p$个数字描述,0代表这个部 ...

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

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

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

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

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

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

  8. POJ 3436:ACM Computer Factory 网络流

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

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

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

随机推荐

  1. Day9 - Python 多线程、进程

    Python之路,Day9, 进程.线程.协程篇   本节内容 操作系统发展史介绍 进程.与线程区别 python GIL全局解释器锁 线程 语法 join 线程锁之Lock\Rlock\信号量 将线 ...

  2. COGS 859. 数列

    /* 先来说一下第一眼看到想出的奇葩方法23333.. 找每个数左右有几个比他小的 前几天刚学了区间第k小的求法 然后... 枚举中间的那个点 对于左区间 二分找到他是第几大 右区间同理 然后 *起来 ...

  3. Java数字、货币值和百分数等的格式化处理

    如果我们用下列语句输出一个数 System.out.println(123456.789); 将会在Console看到输出 123456.789 那么如何得到123,456.789这种格式化的输出呢? ...

  4. (转)C#文件操作

    原文连接:http://www.cnblogs.com/wangshenhe/archive/2012/05/09/2490438.html 文件与文件夹操作主要用到以下几个类: 1.File类: 提 ...

  5. 关于电脑开机不出现桌面即不启动explorer.exe桌面程序--------正解

    针对这个问题,一开始的思路是,把自己写的界面小程序(Win.exe)放在Windows启动文件夹中, 效果到是界面程序自启动了,但是还是先出现的桌面,然后才的启动的界面程序(Win.exe),并不是我 ...

  6. GridView的初级使用

    使用GridView自带的分页功能,需要激发PageIndexChanging protected void gvNewsList_PageIndexChanging(object sender, G ...

  7. [转]Delphi中进行延时的4种方法

    1.挂起,不占CPU sleep 2.不挂起,占cpu procedure Delay(msecs:integer); var FirstTickCount:longint; begin FirstT ...

  8. [Python笔记]第三篇:深浅拷贝、函数

    本篇主要内容:深浅拷贝,自定义函数,三目运算,lambda表达式, 深浅拷贝 一.数字和字符串 对于 数字 和 字符串 而言,赋值.浅拷贝和深拷贝无意义,因为其永远指向同一个内存地址. import ...

  9. python的bind函数

    # -*- coding:utf-8 -*- class Functor(object): def __init__(self, func, index=0, *args, **kwargs): se ...

  10. Unity扩展编辑器--类型3:Custom Editors

    Custom Editors 加速游戏制作过程的关键是为哪些频繁使用的组件创建自定义的编辑器,为了举例,我们将会使用下面这个极其简单的脚本进行讲解,它的作用是始终保持一个对象注视某一点. public ...