ACM Computer Factory

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9963   Accepted: 3738   Special Judge

题目链接:http://poj.org/problem?id=3436

Description:

As you know, all the computers used for ACM contests must be identical, so the participants compete on equal terms. That is why all these computers are historically produced at the same factory.

Every ACM computer consists of P parts. When all these parts are present, the computer is ready and can be shipped to one of the numerous ACM contests.

Computer manufacturing is fully automated by using N various machines. Each machine removes some parts from a half-finished computer and adds some new parts (removing of parts is sometimes necessary as the parts cannot be added to a computer in arbitrary order). Each machine is described by its performance (measured in computers per hour), input and output specification.

Input specification describes which parts must be present in a half-finished computer for the machine to be able to operate on it. The specification is a set of P numbers 0, 1 or 2 (one number for each part), where 0 means that corresponding part must not be present, 1 — the part is required, 2 — presence of the part doesn't matter.

Output specification describes the result of the operation, and is a set of P numbers 0 or 1, where 0 means that the part is absent, 1 — the part is present.

The machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.

After many years of operation the overall performance of the ACM Computer Factory became insufficient for satisfying the growing contest needs. That is why ACM directorate decided to upgrade the factory.

As different machines were installed in different time periods, they were often not optimally connected to the existing factory machines. It was noted that the easiest way to upgrade the factory is to rearrange production lines. ACM directorate decided to entrust you with solving this problem.

Input

Input file contains integers P N, then N descriptions of the machines. The description of ith machine is represented as by 2 P + 1 integers Qi Si,1 Si,2...Si,P Di,1 Di,2...Di,P, where Qi specifies performance, Si,j — input specification for part j, Di,k — output specification for part k.

Constraints

1 ≤ P ≤ 10, 1 ≤ N ≤ 50, 1 ≤ Qi ≤ 10000

Output

Output the maximum possible overall performance, then M — number of connections that must be made, then M descriptions of the connections. Each connection between machines A and B must be described by three positive numbers A B W, where W is the number of computers delivered from A to B per hour.

If several solutions exist, output any of them.

Sample Input

Sample input 1
3 4
15 0 0 0 0 1 0
10 0 0 0 0 1 1
30 0 1 2 1 1 1
3 0 2 1 1 1 1
Sample input 2
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
Sample input 3
2 2
100 0 0 1 0
200 0 1 1 1

Sample Output

Sample output 1
25 2
1 3 15
2 3 10
Sample output 2
4 5
1 3 3
3 5 3
1 2 1
2 4 1
4 5 1
Sample output 3
0 0

Hint

Bold texts appearing in the sample sections are informative and do not form part of the actual data.
 
题意:
这个题意难度有点大呀TnT。
简单说就是给出n个机器,每个机器都有一个pi代表生产效率,然后后面有2*p个数,前p个代表输入规范,后p个代表输出规范。这里输入输出规范的意思就是这台机器可以把输入规范转化为输出规范。
输入规范里面0就是这里没有零件,1就是这里必须有零件,2就是这里可有可不有;输出规范里面就只有0,1,意义同上。
现在问最多可以生产出多少台电脑(假设机器的配合不消耗时间= =),只有输出规范全为1的机器可以生产电脑。
 

题解:

这题用最大流来做。首先建立一个超级源点和超级汇点,超级源点连上输入规范全为0,或有0也有2的机器,因为这些机器可以“无中生有”,边权为无穷大。

然后所有输出规范为1的机器就连向超级汇点,毕竟此时可以生成电脑,边权也为无穷大。

然后建立可以相互可达的机器之间的边,这里由于每个点有个生产效率的权值,所以我们考虑把点拆开为一条权值为其生产效率的有向边,拆成的两个点分别代表入读点和出度点。这样可以限定一条生产线上的生产效率。

然后直接跑最大流就好了~

最后统计结果的时候就随便统计一下就好了...毕竟special judge。如果一个出度点到一个入读点的边上面有流量,就代表了两个点之间有合作关系,就输出这两个点。

代码如下:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#define INF 99999999
using namespace std; const int N = ;
int P,n,tot;
int p[N],m[N][N],head[N],cur[N],d[N]; struct Edge{
int u,v,c,flow,next;
}e[N<<];
void adde(int u,int v,int w,int f){
e[tot].v=v;e[tot].u=u;e[tot].c=w;e[tot].flow=f;
e[tot].next=head[u];head[u]=tot++;
}
bool bfs(int s,int t){
for(int i=;i<=*n+;i++) d[i]=;d[s]=;
queue <int > q;q.push(s);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(!d[v] && e[i].c>e[i].flow){
d[v]=d[u]+;
q.push(v);
}
}
}
return d[t]!=;
}
int dfs(int s,int a){
if(s==*n+ || a==) return a;
int flow = ;
for(int &i=cur[s];i!=-;i=e[i].next){
int v=e[i].v,f;
if(d[v]!=d[s]+) continue ;
f=dfs(v,min(a,e[i].c-e[i].flow));
if(f){
e[i].flow+=f;
e[i^].flow-=f;
a-=f;
flow+=f;
if(a==) break;
}
}
if(!flow) d[s]=-;
return flow;
}
int main(){
scanf("%d%d",&P,&n);
memset(head,-,sizeof(head));
for(int i=;i<=n;i++){
scanf("%d",&p[i]);
for(int j=;j<=*P;j++) scanf("%d",&m[i][j]);
} for(int i=;i<=n;i++){
adde(i,i+n,p[i],);
adde(i+n,i,,);
int flag1=,flag2=;
for(int j=;j<=P;j++){
if(m[i][j]==) flag1=;
if(m[i][j+P]!=) flag2=;
}
if(flag1) adde(,i,INF,),adde(i,,,);
if(flag2) adde(i+n,*n+,INF,),adde(*n+,i+n,,);
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==j) continue ;
bool ok = true ;
for(int k=P+;k<=P*;k++){
int now = k-P;
if(m[j][now]==) continue ;
if(m[i][k]!=m[j][now]) ok=false;
}
if(ok){
adde(i+n,j,INF,);
adde(j,i+n,,);
}
}
} int max_flow = ;
while(bfs(,*n+)){
for(int i=;i<=*n+;i++) cur[i]=head[i];
max_flow+=dfs(,INF);
}
printf("%d ",max_flow);
int tot=;
vector <pair<int,int> > ans[N];
for(int i=+n;i<=*n;i++){
for(int j=head[i];j!=-;j=e[j].next){
int v=e[j].v;
if(v!=*n+ && v!= && e[j].flow && v!=i-n) ans[i-n].push_back(make_pair(v,e[j].flow)),tot++;
}
}
printf("%d\n",tot);
for(int i=;i<=n;i++)
for(int j=;j<ans[i].size();j++){
printf("%d %d %d\n",i,ans[i][j].first,ans[i][j].second);
}
return ;
}

POJ3436:ACM Computer Factory(最大流)的更多相关文章

  1. POJ3436 ACM Computer Factory —— 最大流

    题目链接:https://vjudge.net/problem/POJ-3436 ACM Computer Factory Time Limit: 1000MS   Memory Limit: 655 ...

  2. poj-3436.ACM Computer Factory(最大流 + 多源多汇 + 结点容量 + 路径打印 + 流量统计)

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10940   Accepted:  ...

  3. POJ3436 ACM Computer Factory(最大流)

    题目链接. 分析: 题意很难懂. 大体是这样的:给每个点的具体情况,1.容量 2.进入状态 3.出去状态.求最大流. 因为有很多点,所以如果一个点的出去状态满足另一个点的进入状态,则这两个点可以连一条 ...

  4. POJ-3436 ACM Computer Factory 最大流 为何拆点

    题目链接:https://cn.vjudge.net/problem/POJ-3436 题意 懒得翻,找了个题意. 流水线上有N台机器装电脑,电脑有P个部件,每台机器有三个参数,产量,输入规格,输出规 ...

  5. POJ3436 ACM Computer Factory 【最大流】

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5412   Accepted: 1 ...

  6. poj3436 ACM Computer Factory, 最大流,输出路径

    POJ 3436 ACM Computer Factory 电脑公司生产电脑有N个机器.每一个机器单位时间产量为Qi. 电脑由P个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...

  7. POJ3436 ACM Computer Factory(最大流/Dinic)题解

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8944   Accepted: 3 ...

  8. POJ-3436 ACM Computer Factory(网络流EK)

    As you know, all the computers used for ACM contests must be identical, so the participants compete ...

  9. Poj 3436 ACM Computer Factory (最大流)

    题目链接: Poj 3436 ACM Computer Factory 题目描述: n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑? 解题 ...

  10. POJ-3436:ACM Computer Factory (Dinic最大流)

    题目链接:http://poj.org/problem?id=3436 解题心得: 题目真的是超级复杂,但解出来就是一个网络流,建图稍显复杂.其实提炼出来就是一个工厂n个加工机器,每个机器有一个效率w ...

随机推荐

  1. 博弈dp 以I Love this Game! POJ - 1678 为例

    写在前面的话 知识基础:一些基础的博弈论的方法,动态规划的一些知识 前言:博弈论就是一些关于策略或者游戏之间的最优解,动态规划就是对于一些状态之间转移的一些递推式(or 递归),dp分为很多很多种,比 ...

  2. intellij idea之git执行打标签(tag)和删除标签

    intellij idea 版本为2017.2.6 进入Version Control-->log 1.在之前版本中,右键,新建标签 2.输入标签名称,建议输入版本号的方式 3.push标签 由 ...

  3. PHP.38-TP框架商城应用实例-后台14-商品管理-商品扩展分类的删除、修改

    商品分类删除 1.删除商品时,根据商品id删除扩展分类表数据 商品扩展分类修改 1.在控制器GoodsController.class.php/edit()中根据商品id取出对应的所有扩展分类 2.在 ...

  4. 初步学习pg_control文件之十二

    接前问,初步学习pg_control文件之十一,再来看下面这个 XLogRecPtr minRecoveryPoint; 看其注释: * minRecoveryPoint is updated to ...

  5. c/c++ 随机数生成

    当程序需要一个随机数时有两种情况下使用: 1.程序中只需使用一次随机数,则调用rand()函数即可 2.程序需要多次使用随机数,那么需要使用srand()函数生成随机数种子在调用rand()函数保证每 ...

  6. struts2官方 中文教程 系列九:Debugging Struts

    介绍 在Struts 2 web应用程序的开发过程中,您可能希望查看由Struts 2框架管理的信息.本教程将介绍两种工具,您可以使用它们来查看.一个工具是Struts 2的配置插件,另一个是调试拦截 ...

  7. Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org/apache/hadoop/hbase/

    Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org/apache/hadoop/hbase/ ...

  8. Hibernate-ORM:04.Hibernate中的get()和load()

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客会讲如何用get()或load()查询单个对象和对缓存的简单操作,以及他俩的区别和相同(前面有的那些配 ...

  9. 转:C#微信公众号开发之接收事件推送与消息排重的方法

    本文实例讲述了C#微信公众号开发之接收事件推送与消息排重的方法.分享给大家供大家参考.具体分析如下: 微信服务器在5秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次.这样的话,问题就来了.有这 ...

  10. CTS测试笔记

    电脑安装12.4乌班图系统 更新源 (1) 打开ubuntu software center (2) 电脑左上角选择edit→software sources…→点击download from,选择o ...