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个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...
随机推荐
- POJ 1986(LCA and RMQ)
题意:给定一棵树,求任意两点之间的距离. 思路:由于树的特殊性,所以任意两点之间的路径是唯一的.u到v的距离等于dis(u) + dis(v) - 2 * dis(lca(u, v)); 其中dis( ...
- java定时器,Spring定时器和Quartz定时器
一.java定时器的应用 其实java很早就有解决定时器任务的方法了,java提供了了类java.util.TimerTask类基于线程的方式来实现定时任务的操作,然后再提供java.util.Tim ...
- servlet 配置到服务器
最近写了个安卓项目,服务端用的servlet.因为第一次写java项目,写完如何发布不是太清除,于是把这回经理写出来,一来做个记录,二来也给和我同样经历的朋友一点启示. 首先配置你的java主机和你的 ...
- HDU3480
题意:给你n个数,然后让你分成m个集合,每个集合有一个值(最大值减最小值,然后平方),求整个集合的可能最小值. 思路:因为每个集合里的值只和最大和最小值有关,所以很容易想到先排序,然后用DP可求得解, ...
- HDU5311
题意:给一个指定的字符串a,要求分成三段,然后再给定另外一个字符串b,要求a中的三段能否在b中找到. 思路:枚举+模拟,首先枚举给定的字符串a,因为分成三段,所以一共有(1+9)*9/2种情况,对于分 ...
- HTML (1)href与Action,get post
1. href与Action的区别 href只能get参数,action能get参数又能post参数 href一般用于单个连接,可以带参数(URL重写),是采用get方式请求的,在地址栏中可以看到 ...
- CXF自动生成客户端
官网下载apache-cxf-3.1.6,bin目录下.配置环境变量,生成客户端 http://blog.csdn.net/jaune161/article/details/25499939 http ...
- 64位Window操作系统下,Orcal数据访问服务器端和客户端版本对应与通讯问题
最近做一个小系统,需要在客户现场搭建数据库环境.之前我们一直访问的是公司的一个测试库,现在需要在现场开发,现场的Orcal服务器是12C ,我们本不打算重装服务器端orcal,故将我们自己电脑的orc ...
- CountDownLatch 和 CyclicBarrier 的运用及实现原理
I.CountDownLatch 和 CyclicBarrier 的运用 CountDownlatch: 定义: 其是一个线程同步的辅助工具,通过它可以做到使一条线程一直阻塞等待,直到其他线程完成其所 ...
- CentOS6.5安装LAMP环境APACHE的安装
1.卸载apr.apr-util [root@centos6 LAMP]# yum remove apr apr-util 2.编译安装apr-1.5.1.tar.gz [root@centos6 L ...