题目链接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=90592#problem/B
题目大意
Time Limit: | Memory Limit: | |||
Total Submissions: | Accepted: | 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
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
Output specification describes the result of the operation, and is a set of
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
Constraints
1 ≤
Output
Output the maximum possible overall performance, then
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
Source
题意:
输入P和N,P表示零件总类个数,N表示机器台数,然后输入N行,每行的第一个元素为该机器的最大加工零件个数,接下去的P个元素为每台机器对应的P个零件的输入信息,0 表示 该台机器不能用于加工 Pj(1<= j <= P) 这个零件,1表示如果要在该台机器上加工就必须需要Pj这个零件,2表示Pj这个零件的有无对该台机器的加工不产生任何影响,然后又是P个元素,对应P个零部件在该台机器上的输出,如果Pj 对应的元素为0,那么表示该台机器不能产生Pj这个零部件,反之当Pj对应的元素为1,则表示该台机器可以产生零部件Pj
第一次做网络流题目 总是错 贴的也是别人代码
#include #include using namespace std; const int inf=10001; int s; //超级源 int t; //超级汇 int n; //总结点数(包括超级源、超级汇) int p; //每台机器的部分数 int cap[52][52];// 边容量 int min(int a,int b) { return a<b?a:b; } /*利用BFS找增广链求网络最大流*/ int maxflow(void) { int queue[52]; int head,tail; int pre[52]; //结点i的前驱 int minflow; int flow = 0; int x,y; while(true) { memset(pre, -1, sizeof(pre)); for(queue[head=tail=0]=s;head<=tail;head++) { x=queue[head]; for(int i=0;(i0 && pre[i]==-1) //当结点u指向i的边存在,且i还没有标记前驱时 { pre[i]=x;//记录结点i的前驱为u queue[++tail]=i; } } if(pre[t]==-1) break;//BFS后汇点没有被标记,则跳出while,已经不存在增广链 minflow=inf;//初始化 for(x=pre[y=t];y!=s;)//回溯 { if(cap[x][y] < minflow) minflow=cap[x][y];//寻找当前增广链中最小容量的边,记录其边权(容量) y=x; x=pre[y]; } for(x=pre[y=t];y!=s;) //当前增广链 流量调整 { cap[x][y] -= minflow; //正向弧容量减少 cap[y][x] += minflow; //反向弧容量增加 y=x; x=pre[y]; } flow += minflow; //最大流=每次寻得的增广链的调整量之和 } return flow;//返回最大流 } int main(int i,int j,int k) { int in[52][21]; int out[52][3]; int backup[52][52];//备份图 int N; //除超级源、超级汇以外的总结点数 int line; //生产线数(容量发生变化的边数) int flow; //最大流 while (cin>>p>>N) { /*Initial*/ memset(cap,0,sizeof(cap)); //所有正向弧和反向弧的容量都初始化为0 s=0;//超级源 t=N+1; //超级汇 n=N+2; //总结点数+2 line=0; //记录变化的边的数量(生产线数量) /*Input*/ for(i=1;i<=N;i++) for(j=0;j<2 p="" 1="" j="" cin="">>in[i][j]; //用一个数列存储第i个结点的信息 in[i][0] 为结点i的容量 bool flag_s, flag_t; for(i=1;i<=N;i++) { flag_s=flag_t=true; for(k=0;k
i,边容量为i的容量 if(flag_t) cap[i][t]=in[i][0]; //当输出列全为1时,i->t,边容量为i的容量 bool flag=true; for(j=1;j<=N;j++) if(i!=j) { flag=true; for(k=0;(k
j,边容量为i的容量和j的容量的最小值 } } /*利用BFS找增广链求网络最大流*/ memcpy(backup, cap, sizeof(cap)); //把寻找增广链前的图的容量信息复制 flow=maxflow(); //返回最大流 /*Output*/ for(i=1;i<=N;i++) //注意范围,排除了含超级源和超级汇的边 for(j=1;j<=N;j++) if (cap[i][j] < backup[i][j])//比较调整前后的边权,若容量减少了,则输出这条边的信息 { out[line][0]=i; //i,j为生产线的两端点 out[line][1]=j; out[line][2]=backup[i][j] - cap[i][j];//变化的流量值(该生产线的最大生产量) line++; } cout<<flow<<' '<<line<<endl; for(i=0;i<line;i++) cout<<out[i][0]<<' '<<out[i][1]<<' '<<out[i][2]<<endl; } return 0; }