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. 解决CentOS下boost安装后不能使用的问题

    先说一说整个经历. 因为之前没有注意到gcc4.8.5比较旧,就已经安装好boost了,当时已经可以使用了,后来发现gcc太老了,一些软件安装需要比较新的gcc支持,所以决定升级gcc,结果boost ...

  2. PHP的自定义模板引擎

    前面的话 在大多数的项目组中,开发一个Web程序都会出现这样的流程:计划文档提交之后,前端工程师制作了网站的外观模型,然后把它交给后端工程师,它们使用后端代码实现程序逻辑,同时使用外观模型做成基本架构 ...

  3. .NET Runtime at IP 791F7E06 (79140000) with exit code 80131506.

    事件類型: 錯誤 事件來源: .NET Runtime 事件類別目錄: 無 事件識別碼: 1023 日期: 2015/12/15 時間: 上午 10:18:52 使用者: N/A 電腦: KM-ERP ...

  4. Dart语言学习(十) Dart流程控制语句

    一.条件语句:if.if...elseif.if...elseif...else int score = 95; if (score >=90) { print('优秀'); } else if ...

  5. 【转载】使用阿里云code和git管理项目

    使用代码云托管和git来管理项目可以使多客户端和多人开发更加高效.通过对比github,bitbucket和国内一些云托管服务发现阿里云在项目空间和传输速度及稳定性上更能满足公司开发的要求.本文将介绍 ...

  6. 一起探讨Go 语言为什么能成功?

    导读 两位创造者Rob Pike和Robert Griesemer一起探讨了Go成功的原因. 常言道,历史不会重演,但总会惊人的相似. 如果您想创建一种编程语言,多向那些有经验的人士学习,他们有很多可 ...

  7. 第2节 Scala中面向对象编程:12、13、14、15、16、trait

    6.4.  Scala中面向对象编程之trait 6.4.1.    将trait作为接口使用 Scala中的trait是一种特殊的概念: 首先先将trait作为接口使用,此时的trait就与Java ...

  8. Dynamic Programming(动态规划)

    钢材分段问题 #include<iostream> #include<vector> using namespace std; class Solution { public: ...

  9. Maven项目-端口被占用java.net.BindException: Address already in use: JVM_Bind <null>:8080解决方法

    异常显示: 问题所在:之前启动的tomcat未停止,端口被占用. 解决方法: 养成良好的习惯,用完之后停掉服务.

  10. 排序--选择排序Selection Sort Java实现

    基本原理 选择排序的简单原理:选择排序算法通过从未排序部分重复查找最小元素(考虑升序)并将其放在开头来对数组进行排序. 将数组两个子数组: 已排序子数组 未排序子数组 选择排序中每次循环都会从未排序子 ...