POJ 3436: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 j, Di,k— output specification for part k.
Constraints
1 ≤ P ≤ 10, 1 ≤ N ≤ 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
这个题的题意是现在有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 网络流的更多相关文章
- POJ - 3436 ACM Computer Factory 网络流
POJ-3436:http://poj.org/problem?id=3436 题意 组配计算机,每个机器的能力为x,只能处理一定条件的计算机,能输出特定的计算机配置.进去的要求有1,进来的计算机这个 ...
- POJ 3436 ACM Computer Factory (网络流,最大流)
POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...
- Poj 3436 ACM Computer Factory (最大流)
题目链接: Poj 3436 ACM Computer Factory 题目描述: n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑? 解题 ...
- 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 ...
- POJ 3436 ACM Computer Factory 最大流,拆点 难度:1
题目 http://poj.org/problem?id=3436 题意 有一条生产线,生产的产品共有p个(p<=10)零件,生产线上共有n台(n<=50)机器,每台机器可以每小时加工Qi ...
- POJ - 3436 ACM Computer Factory(最大流)
https://vjudge.net/problem/POJ-3436 题目描述: 正如你所知道的,ACM 竞赛中所有竞赛队伍使用的计算机必须是相同的,以保证参赛者在公平的环境下竞争.这就是所有这些 ...
- POJ 3436 ACM Computer Factory(最大流+路径输出)
http://poj.org/problem?id=3436 题意: 每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了.计算机的生产过程通过N台不同的机器来完成,每台机器用它的性 ...
- POJ 3436 ACM Computer Factory (拆点+输出解)
[题意]每台计算机由P个零件组成,工厂里有n台机器,每台机器针对P个零件有不同的输入输出规格,现在给出每台机器每小时的产量,问如何建立流水线(连接各机器)使得每小时生产的计算机最多. 网络流的建图真的 ...
- POJ 3436 ACM Computer Factory
题意: 为了追求ACM比赛的公平性,所有用作ACM比赛的电脑性能是一样的,而ACM董事会专门有一条生产线来生产这样的电脑,随着比赛规模的越来越大,生产线的生产能力不能满足需要,所以说ACM董事会想 ...
- poj 3436 ACM Computer Factory 最大流+记录路径
题目 题意: 每一个机器有一个物品最大工作数量,还有一个对什么物品进行加工,加工后的物品是什么样.给你无限多个初始都是000....的机器,你需要找出来经过这些机器操作后最多有多少成功的机器(111. ...
随机推荐
- [ DLPytorch ] 文本分类&图像增强
图像增强 图像增广(image augmentation)技术通过对训练图像做一系列随机改变,来产生相似但又不同的训练样本,从而扩大训练数据集的规模.图像增广的另一种解释是,随机改变训练样本可以降低模 ...
- Failed to read candidate component class
今天编程时遇到了Failed to read candidate component class 这个异常,查了好久终于发现了是因为jdk的版本不对,所以报了这个错.
- redhat 7.6 iptables 配置
1.查看iptables默认表(filter) iptables -L -n 2.iptables 默认内链(filter)表三种: INPUT:处理进入防火墙的数据包 FORWARD:源自其他计算机 ...
- [A]List`1[MyObject] cannot be cast to [B]List`1[MyObject]
Description I have created a small class in a single ASP.NET 4.5 web forms page that is instantiated ...
- Python中神秘的-5到256
注:本文不区分作为编程语言的Python和作为语言实现的Python.后者均默认为CPython. 了解他人对Python源代码的掌握情况,我喜欢问这样一个问题 请问,在Python中,256和257 ...
- ios APP进程杀死之后和APP在后台接收到推送点击跳转到任意界面处理
https://www.jianshu.com/p/ce0dc53eb627 https://www.cnblogs.com/er-dai-ma-nong/p/5584724.html github: ...
- 吴裕雄--天生自然ORACLE数据库学习笔记:其它数据对象
create index emp_deptno_index on emp(deptno) pctfree tablespace users; create bitmap index emp_salar ...
- (任意进制转换)将 r 进制数转成 k 进制数
我们知道任意进制转换为十进制,都是乘以基数的多少次方,然后相加: 十进制转换为任意进制,都是除以基数,然后倒着取余数: 所以这里是用十进制数中转,实现任意进制数的转换 #include<iost ...
- 利用Session实现三天免登陆
什么是Session Session:在计算机中,尤其是在网络应用中,称为“会话控制”.(百度百科) Session:服务器端的数据存储技术. Session要解决什么问题 一个用户的不同请求(重定位 ...
- C++ 结构体指针理解
上一篇基础链接https://www.cnblogs.com/xuexidememeda/p/12283845.html 主要说一下链表里面双重指针 先说一下结构体 typedef struct LN ...