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个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...
随机推荐
- HTML5之选择上传图片文件
- python学习之成员信息增删改查
主要实现了成员信息的增加,修改,查询,和删除功能,写着玩玩,在写的过程中,遇到的问题,旧新成员信息数据的合并,手机号和邮箱的验证,#!/usr/bin/env python# coding=utf8# ...
- (转)Mac OS X中配置Apache
我使用的Mac OS X版本是10.8.2,Mac自带了Apache环境. 启动Apache 设置虚拟主机 启动Apache 打开“终端(terminal)”,输入 sudo apachectl -v ...
- 创建 序列 存储过程 job
掌握了 oracle中的 dbms_lock 函数,该函数 主要用于暂停执行的程序 1.用意 写job 以10分钟 为单元,前10分钟 从 1到10 插入测试表, 中间10分钟从 11到20插入测试表 ...
- CSS样式的优势
为什么使用css样式来设置网页的外观样式呢?下面是一段文字,我们想把“超酷的互联网”.“服务及时贴心”.“有趣易学”这三个短语的文本颜色设置为红色,这时就 可以通过设置样式来设置,而且只需要编写一条c ...
- jQuery中的综合动画
所谓综合动画,就是在链式表达式依次执行相关animate函数,其中的参数是以键值对的方式存在的. 如下示例,就展示了一个基本的综合动画. <!DOCTYPE html PUBLIC " ...
- Javascript模块化编程 require.js使用详解
一.为什么用require.js,产生的背景 最早的时候,所有Javascript代码都写在一个文件里面,只要加载这一个文件就够了.后来,代码越来越多,一个文件不够了,必须分成多个文件,依次加载. & ...
- python中函数的默认参数陷阱问题
其实也不能说是陷阱,只是一个不容易注意到的地方,尤其是有其他java/c++类编程语言经验的人员,这里涉及到python的一个特点,所以笔者说是陷阱只是一个噱头而已. def test(item, b ...
- eclipse 编辑 python 中文乱码的解决方案
今天在学习python时做了一个用户输入一个目录地址,再输入内容,然后将输入的内容存入输入的目录文件中: 具体代码如下: #coding:utf- ''' Created on -- @author: ...
- android中的margin和padding
Android的Margin和Padding跟Html的是一样的.如下图所示:黄色部分为Padding,灰色部分为Margin. 通俗的理解: Padding 为内边框,指该控件内部内容,如文本/图片 ...