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. ...
随机推荐
- 监控Tomcat状态!(重点)
方法一:开发JAVA监控页面 [root@localhost ~]# mkdir /usr/local/tomcat8/webapps/memtest/[root@localhost ~]# cd / ...
- php学习函数如何执行的
入口栈abc(4)--------abc(4)------abc(3)-----abc(2)再返回上一层栈,执行完后返回上一层.输出$n=2-------$n=2-------$n=3
- ng-class 动态设置css
可使用ng-class 动态设置class ,设置disable后,发现ng-click 居然还可以使用,不知什么原因. <li ng-class="{disabled:!first} ...
- 使用maven搭建web项目
在pom.xml中添加java ee相关的三个依赖包:<scope> jar的有效范围 provided 表示编译期生效,不会打包发布到 tomcat 中 <properties&g ...
- CSS - 权重,样式优先级
关于CSS权重,一套计算公式来去计算,就是 CSS Specificity,我们称为CSS 特性或称非凡性,它是一个衡量CSS值优先级的一个标准. 遇到样式应用问题,计算一下权重就知道优先级. 具体规 ...
- LockSupport源码分析
LockSupport提供park()和unpark()方法实现线程阻塞和唤醒.底层实现是通过sun.misc.Unsafe的park和unpark. 关于sun.misc.Unsafe的说明请参见我 ...
- HDU 2680 最短路 迪杰斯特拉算法 添加超级源点
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 01初步启动Hadoop服务
1.rz命令将hadoop压缩包上传至Linux服务器中 2.tar -zxvf hadoop-2.7.7.tar.gz(解压即可用) 3.将解压出来的hadoop移到想要放的位置 mv hadoop ...
- python爬虫(七) mozillacookiejar
MozillaCookiejar 保存百度得Cookiejar信息: from urllib import request from urllib import parse from http.coo ...
- windows下svn post-commit的实现
前言: 好的!在结束了上一博客教程的Subversion安装之后.我们开始了下一项工作,windows版本下 svn post-commit的实现.说实话,这方面的知识网上的知识并不是很多~~~~~~ ...