您的位置:首页 > 其它

POJ 3436 ACM Computer Factory

2018-01-11 21:31 429 查看
ACM Computer Factory

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 8628 Accepted: 3138 Special Judge
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,
4000
 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.

题意复杂到爆炸,为了追求ACM比赛的公平性,所有用作ACM比赛的电脑性能是一样的,而ACM董事会专门有一条生产线来生产这样的电脑,随着比赛规模的越来越大,生产线的生产能力不能满足需要,所以说ACM董事会想要重新建造一条生产线。

        生产线是全自动化的,所以需要机器来组成生产线,给定有多少中种机器,标准ACM用电脑有多少部份,每种机器将什么样的ACM电脑半成品处理成什么样的电脑半成品(对于输入的电脑半成品,每部分有0,1,2三种状态:代表着 0、这部分必须没有我才能处理,1、这部分必须有我才能处理,2、这部分有没有我都能处理。对于输出的电脑半成品有0,1两种状态:代表着0,处理完后的电脑半成品里没有这部分,1、处理完的电脑半成品有这部分),每一个机器每小时可以处理Q个半成品(输入数据中的Qi)。

        求组装好的成产线的最大工作效率(每小时最多生成多少成品,成品的定义就是所有部分的状态都是“1”),和每两个机器之间的流量。

网络流建立一个源点汇点,然后记得拆点不拆的话会出现一条生产线中的点使用好几次,建图到绝望,参考了博客:点击打开链接

#include<stdio.h>
#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
int c[300][300];
int c1[300][300];
int f[300][300];
int a[300],pre[300];
struct node
{
int r;
int in[15];
int out[15];
} ma[60];
struct node1
{
int xx;
int yy;
int cc;
} aa[300];
int ans,sum,p,n,res,k,kk;
int link(node x,node y)
{
for(int i=1; i<=p; i++)
{
if(x.out[i]!=y.in[i]&&y.in[i]!=2)
{
return 0;
}
}
return 1;
}
void ek(int s,int t)
{
queue<int>q;
sum=0;
ans=0;
while(1)
{
memset(a,0,sizeof(a));
a[s]=inf;
q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int v=s; v<=t; v++)
{
if(!a[v]&&c[u][v]>f[u][v])
{
a[v]=min(a[u],c[u][v]-f[u][v]);
q.push(v);
pre[v]=u;
}
}
}
if(!a[t]) break;
for(int u=t; u!=s; u=pre[u])
{
f[pre[u]][u]+=a[t];
f[u][pre[u]]-=a[t];
c1[pre[u]][u]-=a[t];
c1[u][pre[u]]+=a[t];
}
sum+=a[t];
}
}
int main()
{
while(~scanf("%d%d",&p,&n))
{
memset(c,0,sizeof(c));
memset(f,0,sizeof(f));
for(int i=1; i<=p; i++)
{
ma[1].in[i]=0;
ma[1].out[i]=0;
ma[n+2].in[i]=1;
ma[n+2].out[i]=1;
}
ma[1].r=inf;
ma[n+2].r=inf;
for(int i=2; i<=n+1; i++)
{
scanf("%d",&ma[i].r);
for(int j=1; j<=p; j++)
scanf("%d",&ma[i].in[j]);
for(int j=1; j<=p; j++)
scanf("%d",&ma[i].out[j]);
}
n+=2;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(i==j)
c1[i][j+n]=c[i][j+n]=ma[i].r;
if(link(ma[i],ma[j])&&i!=j)
c1[i+n][j]=c[i+n][j]=ma[i].r;
}
}
ek(1,2*n);
int k=0;
for(int i=2; i<n; i++)
for(int j=2; j<n; j++)
{
if(c[i+n][j]>c1[i+n][j])
{
aa[k].xx=i-1;
aa[k].yy=j-1;
aa[k].cc=c[i+n][j]-c1[i+n][j];
k++;
}
}
printf("%d %d\n",sum,k);
for(int i=0; i<k; i++)
printf("%d %d %d\n",aa[i].xx,aa[i].yy,aa[i].cc);
}
}
/*
两组特殊数据
输入

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

输入
3 11
10 2 2 2 0 0 1
20 2 2 2 0 1 1
30 2 2 2 0 0 1
40 2 2 2 0 1 1
50 2 2 2 0 0 1
1000 2 2 1 1 0 0
50 1 2 2 1 1 1
40 1 2 0 1 1 1
30 1 0 2 1 1 1
20 1 0 0 1 1 1
10 1 2 2 1 1 1

输出
150 10
1 6 10
2 6 20
3 6 30
4 6 40
5 6 50
6 7 50
6 8 40
6 9 30
6 10 20
6 11 10
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: