POJ 3436 ACM Computer Factory
来源:互联网 发布:淘宝手表男士 编辑:程序博客网 时间:2024/05/17 04:01
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 ofP 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 ofith machine is represented as by 2 P + 1 integers Qi Si,1Si,2...Si,P Di,1Di,2...Di,P, whereQi specifies performance, Si,j — input specification for partj, Di,k — output specification for partk.
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, thenM descriptions of the connections. Each connection between machines A and B must be described by three positive numbers A B W, whereW is the number of computers delivered from A to B per hour.
If several solutions exist, output any of them.
Sample Input
Sample input 13 415 0 0 0 0 1 010 0 0 0 0 1 130 0 1 2 1 1 13 0 2 1 1 1 1Sample input 23 55 0 0 0 0 1 0100 0 1 0 1 0 13 0 1 0 1 1 01 1 0 1 1 1 0300 1 1 2 1 1 1Sample input 32 2100 0 0 1 0200 0 1 1 1
Sample Output
Sample output 125 21 3 152 3 10Sample output 24 51 3 33 5 31 2 12 4 14 5 1Sample output 30 0
Hint
Source
#include <iostream>#include <string.h>using namespace std;int a[60][60],b[60][60],val[60];int pre[120],c[120][120];int res[100][100],queue[100000],Res[100][100];int TOP;int sta,end,p,n;int INF=0x7ffffff;int main(){ int EK(); int i,j,m,s,t,k,u,resres,v; while(cin>>p>>n) { memset(c,0,sizeof(c)); memset(Res,0,sizeof(Res)); sta=0; end=2*n+1; for(i=1;i<=n;i++) { cin>>val[i]; c[i][n+i]=val[i]; for(j=1;j<=p;j++) { cin>>a[i][j]; } for(j=1;j<=p;j++) { cin>>b[i][j]; } } for(i=1;i<=n;i++) { for(j=1;j<=p;j++) { if(a[i][j]==1) { break; } } if(j==p+1) { c[0][i]=INF; } for(j=1;j<=p;j++) { if(b[i][j]!=1) { break; } } if(j==p+1) { c[n+i][end]=INF; } for(j=1;j<=n;j++) { if(i!=j) { for(u=1;u<=p;u++) { if(a[j][u]==2||(a[j][u]==b[i][u])) { ; }else { break; } } if(u==p+1) { c[n+i][j]=INF; Res[n+i][j]=INF; } } } } TOP=0;t=0; t=EK(); resres=0; for(i=n+1;i<=2*n;i++) { for(j=1;j<=n;j++) { if(Res[i][j]&&c[i][j]<Res[i][j]) { resres++; } } } cout<<t<<" "<<resres<<endl; for(i=n+1;i<=2*n;i++) { for(j=1;j<=n;j++) { if(Res[i][j]&&c[i][j]<Res[i][j]) { cout<<i-n<<" "<<j<<" "<<Res[i][j]-c[i][j]<<endl; } } } } return 0;}int bfs(){ int i,j,base,top,x; int min1[100000]; base=top=0; queue[top++]=sta; memset(pre,-1,sizeof(pre)); pre[sta]=-2; min1[sta]=INF; while(base<top) { x=queue[base++]; for(i=1;i<=end;i++) { if(pre[i]==-1&&c[x][i]) { min1[i]=min1[x]<c[x][i]? min1[x]:c[x][i]; pre[i]=x; queue[top++]=i; if(i==end) { break; } } } if(i!=end+1) { break; } } if(pre[end]==-1) { return -1; } return min1[end];}int EK(){ int i,j,k,sum=0,t,pre_x,v; while(1) { k=bfs(); if(k==-1) { break; } sum+=k; for(t=end,j=0;t!=sta;t=pre[t]) { pre_x=pre[t]; c[pre_x][t]-=k; c[t][pre_x]+=k; } } return sum;}
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- poj 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- ACM Computer Factory(POJ--3436
- 【Poj 3436】 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- poj 3436 ACM Computer Factory
- POJ 3436 ACM Computer Factory
- poj 3436 ACM Computer Factory
- Hadoop之父勾勒大数据平台未来
- 如何写好Linux设备驱动
- bootload 思想 【BAB 】
- 关于计算机图形学的书籍推荐
- HA 高可用性
- POJ 3436 ACM Computer Factory
- 赠券收集者问题
- Maven入门学习(HelloWorld实例)
- 也说说关于我儿子学中文
- NSFileManager和NSFileHandle
- MTK andriod img copy and svn create trunk
- HDU 2716 水题
- segmentation fault
- 异或的简单用法