POJ 3436 ACM Computer Factory
题意:
为了追求ACM比赛的公平性,所有用作ACM比赛的电脑性能是一样的,而ACM董事会专门有一条生产线来生产这样的电脑,随着比赛规模的越来越大,生产线的生产能力不能满足需要,所以说ACM董事会想要重新建造一条生产线。
生产线是全自动化的,所以需要机器来组成生产线,给定有多少中种机器,标准ACM用电脑有多少部份,每种机器将什么样的ACM电脑半成品处理成什么样的电脑半成品(对于输入的电脑半成品,每部分有0,1,2三种状态:代表着 0、这部分必须没有我才能处理,1、这部分必须有我才能处理,2、这部分有没有我都能处理。对于输出的电脑半成品有0,1两种状态:代表着0,处理完后的电脑半成品里没有这部分,1、处理完的电脑半成品有这部分),每一个机器每小时可以处理Q个半成品(输入数据中的Qi)。
求组装好的成产线的最大工作效率(每小时最多生成多少成品,成品的定义就是所有部分的状态都是“1”)



#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int maxn = ;
const int MOD = 1e9+; int G[maxn][maxn], Layer[maxn], G2[maxn][maxn];
struct node
{
int in[], out[];///第i台机器的输入输出规格
int flow;///第i台机器能放出的最大流量
} P[maxn];
int n, m;///n台机器,每台机器需要m个零件 bool OK(int a,int b)
{
for(int i=; i<=m; i++)
{
if( !(P[a].out[i] == P[b].in[i] || P[b].in[i] == ) )
return false;
}
return true;
} bool BFS(int Star,int End)
{
memset(Layer, , sizeof(Layer));
Layer[Star] = ;
queue<int> Q;
Q.push(Star); while( Q.size() )
{
int s = Q.front();
Q.pop(); if(s == End) return true; for(int i=; i<= End; i++)
{
if(G[s][i] && !Layer[i])
{
Layer[i] = Layer[s] + ;
Q.push(i);
}
}
}
return false;
}
int DFS(int s,int End, int MaxFlow)
{
if(s == End) return MaxFlow; int sFlow = ;///从s出发到达汇点的最大流量 for(int i=; i<=End; i++)
{
int flow = G[s][i]; if( G[s][i]== || Layer[s]+ != Layer[i] ) continue; flow = min(MaxFlow-sFlow, flow);
flow = DFS(i, End, flow);
G[s][i] -= flow;
G[i][s] += flow;
sFlow += flow;
if(sFlow == MaxFlow)
break ;
}
if(sFlow == )
Layer[s] = ;
return sFlow;
} int Dinic(int Star,int End)
{
int ans = ;
while( BFS(Star, End) )
{
ans += DFS(Star, End, INF);
}
return ans;
} int main()
{ while(scanf("%d %d", &m, &n) != EOF)
{
memset(G, , sizeof(G));
memset(P, , sizeof(P));
for(int i=; i<=n; i++)
{
scanf("%d", &P[i].flow);
for(int j=; j<=m; j++)
scanf("%d", &P[i].in[j]); for(int j=; j<=m; j++)
scanf("%d", &P[i].out[j]);
}
for(int i=; i<=m; i++)
{
P[].in[i] = P[].out[i] = ;
P[n+].in[i] = P[n+].out[i] = ;
}
P[].flow = P[n+].flow = INF;
n ++; for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
{
if(i == j)
G[j+n][i] = P[i].flow;
else if( OK(i, j) )
G[i][j+n] = P[i].flow;
}
memcpy(G2, G, sizeof(G));
int MaxFlow = Dinic(, n*);
int num = , a[maxn], b[maxn], c[maxn]; for(int i=; i<n; i++)
for(int j=; j<n; j++)
{
if(i == j)continue; if(G2[i][j+n] > G[i][j+n])
{
a[num] = i, b[num] = j;
c[num++] = G2[i][j+n] - G[i][j+n];
}
} printf("%d %d\n", MaxFlow, num); for(int i=; i<num; i++)
printf("%d %d %d\n", a[i], b[i], c[i]); }
return ;
}
/*
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
*/
POJ 3436 ACM Computer Factory的更多相关文章
- 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 网络流
POJ-3436:http://poj.org/problem?id=3436 题意 组配计算机,每个机器的能力为x,只能处理一定条件的计算机,能输出特定的计算机配置.进去的要求有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(最大流+路径输出)
http://poj.org/problem?id=3436 题意: 每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了.计算机的生产过程通过N台不同的机器来完成,每台机器用它的性 ...
- POJ - 3436 ACM Computer Factory(最大流)
https://vjudge.net/problem/POJ-3436 题目描述: 正如你所知道的,ACM 竞赛中所有竞赛队伍使用的计算机必须是相同的,以保证参赛者在公平的环境下竞争.这就是所有这些 ...
- POJ 3436 ACM Computer Factory (拆点+输出解)
[题意]每台计算机由P个零件组成,工厂里有n台机器,每台机器针对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 最大流+记录路径
题目 题意: 每一个机器有一个物品最大工作数量,还有一个对什么物品进行加工,加工后的物品是什么样.给你无限多个初始都是000....的机器,你需要找出来经过这些机器操作后最多有多少成功的机器(111. ...
随机推荐
- Android(java)学习笔记199:Android中补间动画(Tween Animation)
本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画,可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1. ...
- MySQL日志概述
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/3859866.html ...
- 9.21 noip模拟试题
Problem 1 护花(flower.cpp/c/pas) [题目描述] 约翰留下他的N(N<=100000)只奶牛上山采木.他离开的时候,她们像往常一样悠闲地在草场里吃草.可是,当他回来的时 ...
- web前端:js
内嵌样式<script></script> alert(“123”)弹出对话框 document.write(“test”) 引入方式 <title></ti ...
- Fileupload控件导致500错误
问题: 今天遇到一个问题,用Fileupload控件上传Excel文件,用一个button控件调用“FileUpload1.SaveAs”方法,点击按钮后出现服务器500错误.如下图: 解决方法: 在 ...
- Android开发手记(25) 简单Service的实现
本文将通过实现一个简单的Service发送简单消息,然后通过一个BroadcastReceiver接收Service发送的消息,从而改变一个TextView的文本颜色. 这里,我们需要三个java文件 ...
- Activity和Fragment生命周期变化
情形一:启动应用加载Activity和Fragment Activity::onCreate Fragment::onAttach Fragment::onCreate Fragment::onCre ...
- opencar二次开发常用代码
<?php //创建Registry对象 //注册所有公共类 //创建Front类对象,作为请求分发器(Dispatcher) //根据用户请求(url)创建控制器对象及其动作. // 在Fro ...
- 转-SecureCRT设置
原帖地址:http://www.2cto.com/os/201410/341569.html 一.基本设置 1.修改设置 为了SecureCRT用起来更方便,需要做一些设置,需要修改的有如下几处: 1 ...
- SGU 123.The sum
#include <iostream> using namespace std; int f[50]={0,1,1}; int main(){ int n,s=0; cin>> ...