ACM Computer Factory
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6247   Accepted: 2178   Special Judge

Description

As you know, all the computers used for ACM contests must be identical, so the participants compete on equal terms. That is why all these computers are historically produced at the same factory.

Every ACM computer consists of P parts. When all these parts are present, the computer is ready and can be shipped to one of the numerous ACM contests.

Computer manufacturing is fully automated by using N various machines. Each machine removes some parts from a half-finished computer and adds some new parts (removing of parts is sometimes necessary as the parts cannot be added to a computer in
arbitrary order). Each machine is described by its performance (measured in computers per hour), input and output specification.

Input specification describes which parts must be present in a half-finished computer for the machine to be able to operate on it. The specification is a set of P numbers 0, 1 or 2 (one number for each part), where 0 means that corresponding part
must not be present, 1 — the part is required, 2 — presence of the part doesn't matter.

Output specification describes the result of the operation, and is a set of P numbers 0 or 1, where 0 means that the part is absent, 1 — the part is present.

The machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.

After many years of operation the overall performance of the ACM Computer Factory became insufficient for satisfying the growing contest needs. That is why ACM directorate decided to upgrade the factory.

As different machines were installed in different time periods, they were often not optimally connected to the existing factory machines. It was noted that the easiest way to upgrade the factory is to rearrange production lines. ACM directorate decided to
entrust you with solving this problem.

Input

Input file contains integers P N, then N descriptions of the machines. The description of ith machine is represented as by 2 P + 1 integers Qi Si,1 Si,2...Si,P Di,1 Di,2...Di,P,
where Qi specifies performance, Si,j — input specification for part jDi,k— output specification for part k.

Constraints

1 ≤ P ≤ 10, 1 ≤ ≤ 50, 1 ≤ Qi ≤ 10000

Output

Output the maximum possible overall performance, then M — number of connections that must be made, then M descriptions of the connections. Each connection between machines A and B must be described by three positive numbers A B W,
where W is the number of computers delivered from A to B per hour.

If several solutions exist, output any of them.

Sample Input

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 1
3 0 2 1 1 1 1
Sample input 2
3 5
5 0 0 0 0 1 0
100 0 1 0 1 0 1
3 0 1 0 1 1 0
1 1 0 1 1 1 0
300 1 1 2 1 1 1
Sample input 3
2 2
100 0 0 1 0
200 0 1 1 1

Sample Output

Sample output 1
25 2
1 3 15
2 3 10
Sample output 2
4 5
1 3 3
3 5 3
1 2 1
2 4 1
4 5 1
Sample output 3
0 0

Hint

Bold texts appearing in the sample sections are informative and do not form part of the actual data.

这个题的题意是现在有m台机器,一台机器有n个输入限制(0代表该部件必须没有,1代表该部件必须有,2代表该部件可有可无),n个输出条件。满足输入限制的这台机器才能工作,然后每一台机器都有自己的速度,问这些台机器最多能组成多快的机器,然后每个部分流是多少。

网络流的好题啊。建一个超级源点(输出全部为0,这样才能够与输入全部为0的那些机器接上),一个超级汇点(输入全部为1,这样才能与输出全部为1的机器接上)。然后将每一对能满足输入输出条件的两个点连接起来,容量是两个速度的最小值。求整个网络的最大流。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; const int sum = 201;
const int INF = 99999999;
int cap[sum][sum], flow[sum][sum], in[sum][sum], a[sum], p[sum]; int p2, n; void Edmonds_Karp()
{
int u, t, result = 0;
queue <int> s;
while (s.size())s.pop(); while (1)
{
memset(a, 0, sizeof(a));
memset(p, 0, sizeof(p)); a[0] = INF;
s.push(0); while (s.size())
{
u = s.front();
s.pop(); for (t = 0; t <= n + 1; t++)
{
if (!a[t] && flow[u][t]<cap[u][t])
{
s.push(t);
p[t] = u;
a[t] = min(a[u], cap[u][t] - flow[u][t]);//要和之前的那个点,逐一比较,到M时就是整个路径的最小残量
}
}
}
if (a[n + 1] == 0)
break;
result += a[n + 1]; for (u = n + 1; u != 0; u = p[u])
{
flow[p[u]][u] += a[n + 1];
flow[u][p[u]] -= a[n + 1];
}
}
cout << result << " ";
} int main()
{
//freopen("i.txt", "r", stdin);
//freopen("o.txt", "w", stdout); int i, j, k, u, v, value;
while (scanf("%d%d", &p2, &n) == 2)
{
memset(cap, 0, sizeof(cap));
memset(flow, 0, sizeof(flow)); for (j = 0; j <= 2 * p2 + 1; j++)
{
in[0][j] = 0;
in[n + 1][j] = 1;
} for (i = 1; i <= n; i++)
{
for (j = 0; j<2 * p2 + 1; j++)
{
scanf("%d", &in[i][j]);
}
}
for (i = 0; i <= n + 1; i++)
{
for (j = 0; j <= n + 1; j++)
{
if (i == j)continue; bool f = true;
for (k = 1; k <= p2; k++)
{
if (!(in[j][k] == 2 || in[i][k + p2] == in[j][k]))
f = false;
}
if (f&&i == 0)
{
cap[i][j] = in[j][0];
}
else if (f&&j == n + 1)
{
cap[i][j] = in[i][0];
}
else if (f)
{
cap[i][j] += min(in[i][0], in[j][0]);
}
}
}
Edmonds_Karp(); int cnt = 0;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (flow[i][j]>0)
cnt++;
}
}
cout << cnt << endl; for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (flow[i][j]>0)
{
cout << i << " " << j << " " << flow[i][j] << endl;
}
}
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3436:ACM Computer Factory 网络流的更多相关文章

  1. POJ - 3436 ACM Computer Factory 网络流

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

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

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

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

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

  4. 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 ...

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

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

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

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

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

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

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

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

  9. POJ 3436 ACM Computer Factory

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

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

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

随机推荐

  1. C语言中的快速排序函数

    C库中有自带的快排函数 qsort() ; 它的函数原型为: void qsort(void * , size_t ,size_t size , int (__cdecl *)(const  void ...

  2. Python编程使用PyQT制作视频播放器

    最近研究了Python的两个GUI包,Tkinter和PyQT.这两个GUI包的底层分别是Tcl/Tk和QT.相比之下,我觉得PyQT使用起来更加方便,功能也相对丰富.这一篇用PyQT实现一个视频播放 ...

  3. 单元测试及框架简介 --junit、jmock、mockito、powermock的简单使用

    转 单元测试及框架简介 --junit.jmock.mockito.powermock的简单使用 2013年08月28日 14:33:06 luvinahlc 阅读数:6413 标签: 测试工具单元测 ...

  4. Keras下载的数据集以及预训练模型保存在哪里

    Keras下载的数据集在以下目录中: root\\.keras\datasets Keras下载的预训练模型在以下目录中: root\\.keras\models 在win10系统来说,用户主目录是: ...

  5. hbase入门-相关概念

    hbase入门-概念理解 参考文档: https://blog.csdn.net/luanpeng825485697/article/details/80319552 1.      hbase概念 ...

  6. MIT宣布人工智能独立设系!

    导读 MIT宣布人工智能独立设系!AI与电子工程.计算机科学系将三分天下? MIT 电子工程和计算机科学系(EECS)拆分啦.拆分后分为 3 个学科群(faculty),或者说 3 个系:电子工程(E ...

  7. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)D(树状数组)

    //树状数组中数组的特性,有更巧妙的方法.//我们知道在树状数组中,对于数组tree[i],它所维护的区间为[i−lowbit(i)+1,i]//所以对于tree[2^i],它所维护的区间就为[1,2 ...

  8. FF获6亿美元投资九城或许比贾跃亭更着急

    互联网企业第九城市(以下简称"九城")确认,已透过旗下子公司与总部位于美国加州的法拉第未来公司签定协议,双方共同建立合资公司,在中国制造.营销及运营电动汽车.根据合资公司协议条款, ...

  9. 企业面试问题收集-ssm框架

    springMVC 1)    简单介绍下你对springMVC的理解? Spring MVC Framework有这样一些特点: 1.它是基于组件技术的.全部的应用对象,无论控制器和视图,还是业务对 ...

  10. 利用kali自带的msfvenom工具生成远程控制软件(木马)

    2.生成一个简单的木马 3. 4. 5. 6.接下来生成的winx64muma.exe实际演示 7.将生成的winx64muma.exe在受害者机器上运行 8.在kali下输入msfconsole 9 ...