A - ACM Computer Factory - poj 3436(最大流)
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(最大流)的更多相关文章
- 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 ...
- ACM Computer Factory - poj 3436 (最大流)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5949 Accepted: 2053 Special Judge ...
- (网络流)ACM Computer Factory --POJ --3436
链接: http://poj.org/problem?id=3436 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82835#probl ...
- ACM Computer Factory POJ - 3436 网络流拆点+路径还原
http://poj.org/problem?id=3436 每台电脑有$p$个组成部分,有$n$个工厂加工电脑. 每个工厂对于进入工厂的半成品的每个组成部分都有要求,由$p$个数字描述,0代表这个部 ...
- POJ-3436:ACM Computer Factory (Dinic最大流)
题目链接:http://poj.org/problem?id=3436 解题心得: 题目真的是超级复杂,但解出来就是一个网络流,建图稍显复杂.其实提炼出来就是一个工厂n个加工机器,每个机器有一个效率w ...
- 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个部件,问整个工厂系统在每个小时内最多能加工多少台电脑? 解题 ...
- POJ 3436:ACM Computer Factory 网络流
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6247 Accepted: 2 ...
- poj3436 ACM Computer Factory, 最大流,输出路径
POJ 3436 ACM Computer Factory 电脑公司生产电脑有N个机器.每一个机器单位时间产量为Qi. 电脑由P个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...
随机推荐
- 500 OOPS: vsftpd: refusing to run with writable root inside chroot()解决方法
vsftpd.conf配置文件如下: [root@rusky ~]# cat /etc/vsftpd/vsftpd.conf | grep -v "#" anonymous_ena ...
- BestCoder冠军赛 - 1005 Game 【DP】
[题意] 给出一个set,set中有几个数. 现在给出n个人,环成一圈搞约瑟夫... 开始时从第1号报数,每次从set中随机选出一个数s,等报数到s后,报s的人出圈,其他人继续报数. 最后只剩1人时, ...
- css.day.05.eg
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Swift - 30 - 可变参数
//: Playground - noun: a place where people can play import UIKit // 可变参数一定要放在所有定义参数的最后面, 和其他参数的定义方式 ...
- MySQL 序列使用
MySQL 序列使用 MySQL序列是一组整数:1, 2, 3, ...,由于一张数据表只能有一个字段自增主键, 如果你想实现其他字段也实现自动增加,就可以使用MySQL序列来实现. 本章我们将介绍如 ...
- 五、C# 类
面向对象编程 类是面向对象编程的3个主要特征---封装.继承和多态性---的基础. 封装允许隐藏细节. 继承 继承关系至少涉及两个类,其中一个类(基类)是另一个类的更泛化的版本. 为了从一 ...
- 模拟vector
实现了vector的模板,insert, erase, push_back, iterator #include<iostream> #include<string.h> #i ...
- [FindBugs分析记录]Class defines clone() but doesn't implement Cloneable
官网解释: This class defines a clone() method but the class doesn't implement Cloneable. There are some ...
- FindBugs的Eclipse插件安装与使用
1.FindBugs介绍 FindBugs是一款Java静态代码分析工具,与其他静态分析工具(如Checkstyle和PMD)不同,FindBugs 不注重样式或者格式,它专注于寻找真正的缺陷或者潜在 ...
- Eclipse中使用Maven创建Servlet3.0 Web 项目
摘要 Apache Maven是一个优秀的项目构建和管理工具,许多开源项目都使用Maven进行构建.由于最近工作中要用到Maven,于是这里记录下在Eclipse中使用Maven插件创建一个基于Ser ...