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个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...
随机推荐
- SPOJ 3937 - Wooden Sticks 最长上升子序列LIS
给了n个(n<=5000)木棍的长度hi与宽度wi(均小于10000),现在机器要打磨这些木棍,如果相邻连个木棍hi<=hj并且wi<=wj就不需要调整机器,问如何排序使得机器调整的 ...
- dedecms调用所有顶级栏目最新文章的实现方法
做dedecms的模板,我们会遇到各种各样的调用问题,dedecms列表页调用所有顶级栏目文章列表的方法如下所述: 在文章页面经常使用的是 {dede:arclist orderby='pubdate ...
- qq第3方登录的JS实现方式记录
首先申请qq第3方登录接入的appkey和appid,具体方式http://wiki.connect.qq.com/%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C_oauth ...
- PHP 实现ajax的接收
Ajax界面: 首先,理解本质,就是普通的一个提交在无刷新的情况下发出请求后得到响应,然后去针对你需要 的情况来做行为. <!DOCTYPE html> <html> < ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第三章:搜索、高级过滤和视图模型
在这一章中,我们首先添加一个搜索产品的模块以增强站点的功能,然后使用视图模型而不是ViewBag向视图传递复杂数据. 注意:如果你想按照本章的代码编写示例,你必须完成第二章或者直接从www.apres ...
- android 05
控件:RadioButton CheckedBox RatingBar ProgressBar 下拉列表:ListView Spinner <!-- 单选按钮必须放在单选按钮组当中才能生效 ,并 ...
- Vim中安装delimitMate,auto-pairs插件不能输入中文问题
在安装了delimitMate插件之后发现不能正常使用中文输入了,输入法系统是ibus. 解决办法是在ibus的设置中的“在应用程序中使用内嵌编辑模式”这一项去除就可以正常输入中文了,看来可能是ibu ...
- 我的github代码添加
1.创建一个新的repository: echo "# backupVim" >> README.md git init git add README.md git c ...
- JQuery语法总结和注意事项
1.关于页面元素的引用 通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用do ...
- 初涉JavaScript模式 (11) : 模块模式
引子 这篇算是对第9篇中内容的发散和补充,当时我只是把模块模式中的一些内容简单的归为函数篇中去,在北川的提醒下,我才发觉这是非常不严谨的,于是我把这些内容拎出来,这就是这篇的由来. 什么是模块模式 在 ...