POJ3436 ACM Computer Factory
来源:互联网 发布:网络主播活动策划 编辑:程序博客网 时间:2024/06/03 20:26
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 1Sample 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 1Sample input 3
2 2
100 0 0 1 0
200 0 1 1 1
Sample OutputSample output 1
25 2
1 3 15
2 3 10Sample 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.
思路:
- 最大流+拆点
- 将每个点拆为两个点,两点之间的流为performance。和其他点相连的边容量为INF
#include<stdio.h> #include<string.h> #define E 6000 const int inf=0x3f3f3f3f; int e,head[150]; int dep[150],que[150],cur[150]; struct node { int x,y; int nxt; int c,total; }edge[E]; void addedge(int u,int v,int c) { edge[e].x=u; edge[e].y=v; edge[e].nxt=head[u]; edge[e].c=c; edge[e].total=c; head[u]=e++; edge[e].x=v; edge[e].y=u; edge[e].nxt=head[v]; edge[e].c=0; edge[e].total=0; head[v]=e++; } int maxflow(int s,int t) { int i,j,k,front,rear,top,min,res=0; while(1) { memset(dep,-1,sizeof(dep)); front=0;rear=0; que[rear++]=s; dep[s]=0; while(front!=rear) { i=que[front++]; for(j=head[i];j!=-1;j=edge[j].nxt) if(edge[j].c&&dep[edge[j].y]==-1) { dep[edge[j].y]=dep[i]+1; que[rear++]=edge[j].y; } } if(dep[t]==-1) break; memcpy(cur,head,sizeof(head)); for(i=s,top=0;;) { if(i==t) { min=inf; for(k=0;k<top;k++) if(min>edge[que[k]].c) { min=edge[que[k]].c; front=k; } for(k=0;k<top;k++) { edge[que[k]].c-=min; edge[que[k]^1].c+=min; } res+=min; i=edge[que[top=front]].x; } for(j=cur[i];cur[i]!=-1;j=cur[i]=edge[cur[i]].nxt) if(dep[edge[j].y]==dep[i]+1&&edge[j].c) break; if(cur[i]!=-1) { que[top++]=cur[i]; i=edge[cur[i]].y; } else { if(top==0) break; dep[i]=-1; i=edge[que[--top]].x; } } } return res; } int a[60],b[60][30],g[150][150]; int main() { int n,p,i,j,k; while(scanf("%d%d",&p,&n)!=EOF) { for(i=1;i<=n;i++) { scanf("%d",&a[i]); for(j=0;j<2*p;j++) scanf("%d",&b[i][j]); } e=0;memset(head,-1,sizeof(head)); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { for(k=0;k<p;k++) if((b[i][k+p]==0&&b[j][k]==1)||(b[i][k+p]==1&&b[j][k]==0)) break; if(k>=p) addedge(i+n,j,inf); } for(i=1;i<=n;i++) { for(k=0;k<p;k++) if(b[i][k]==1) break; if(k>=p) addedge(0,i,inf); for(k=0;k<p;k++) if(b[i][k+p]==0) break; if(k>=p) addedge(i+n,n+n+1,inf); } for(i=1;i<=n;i++) addedge(i,i+n,a[i]); int ans=maxflow(0,n+n+1); int num=0; memset(g,0,sizeof(g)); for(i=0;i<e;i++) if(edge[i].c<edge[i].total) g[edge[i].x][edge[i].y]=edge[i].total-edge[i].c; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(g[i+n][j]) num++; printf("%d %d\n",ans,num); for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(g[i+n][j]) printf("%d %d %d\n",i,j,g[i+n][j]); } return 0; }
- poj3436 ACM Computer Factory
- poj3436-ACM Computer Factory
- POJ3436 ACM Computer Factory
- POJ3436 ACM Computer Factory
- poj3436 ACM Computer Factory
- poj3436 ACM Computer Factory
- POJ3436-ACM Computer Factory
- (最大流) poj3436 ACM Computer Factory
- POJ3436 ACM Computer Factory 【最大流】
- [POJ3436]ACM Computer Factory 做题笔记
- POJ3436 ACM Computer Factory【网络流】
- poj3436 ACM Computer Factory 拆点+网络流
- poj3436 ACM Computer Factory, 最大流,输出路径
- poj3436--ACM Computer Factory(最大流,拆点dinic)
- ACM Computer Factory poj3436(网络流-ek)
- POJ3436.ACM Computer Factory(ACM计算机工厂)——最大流+拆点
- POJ3436--ACM Computer Factory--拆点EK算法求最大流
- POJ3436 ACM Computer Factory(dinic最大流+统计不同弧上流量的变化)
- 【莫比乌斯反演】[HYSBZ/BZOJ2301]Problem b
- C++ stringstream的用法|c++ 字符串流 sstream(常用于格式转换)
- 又要留在北京过年了
- 添加module
- webstrom快捷键
- POJ3436 ACM Computer Factory
- 动态代理
- web前端知识结构图
- 1021. 个位数统计 (15)
- javascript语音详解(转载)
- 一起talk C栗子吧(第一百一十三回:C语言实例--线程同步之信号量一)
- 0/1 背包 dp问题
- NGUI移动平台屏幕自适应问题
- Linux C 可变参数的简单例子