POJ3436------ACM Computer Factory
ACM Computer Factory
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.
题意:有N台机器生产电脑,每个电脑有p个部件,,同时每个机器都有一个效率。不同机器能够安装的部件不一定一样,面对不同的机器,我们需要让两个机器对接起来。
题解: 这个题需要通过拆点去做,机器与机器是之间的传输是无穷大的但是机器内部并不是,下面是我画的第一个样例的图示
我用的是EK算法。代码不够精炼,还望海涵。
#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=100;
int in[55][20],out[50][20];
int cap[MAXN][MAXN];
int pre[MAXN];
bool vis[MAXN];
int p,n;
int N=n*2;
bool match(int *a,int *b)
{
for(int i=1;i<=p;i++)
{
if(a[i]==b[i]) continue;
if(b[i]==2) continue;
return false;
}
return true;
}
bool matchs(int *a)
{
for(int i=1;i<=p;i++)
{
if(a[i]==1)
return false;
}
return true;
}
bool matcht(int *b)
{
for(int i=1;i<=p;i++)
{
if(b[i]==0)
return false;
}
return true;
}
bool bfs(int s,int t)
{
memset(pre, -1, sizeof(pre));
queue<int> que;
memset(vis,0 , sizeof(vis));
vis[s]=true;
pre[s]=s;
que.push(s);
int p;
while(!que.empty())
{
p=que.front();
que.pop();
for(int i=0;i<=N;i++)
{
if(!vis[i]&&cap[p][i]>0)
{
vis[i]=true;
pre[i]=p;
if(i==t) return true;
que.push(i);
}
}
}
return false;
}
int EK(int s,int t)
{
int ans=0,d;
while (bfs(s,t))
{
d=INF;
for(int i=t;i!=s;i=pre[i])
d=min(d,cap[pre[i]][i]);
for(int i=t;i!=s;i=pre[i])
{
cap[pre[i]][i]-=d;
cap[i][pre[i]]+=d;
}
ans+=d;
}
return ans;
}
int main()
{
while(scanf("%d%d",&p,&n )!=EOF)
{
memset(cap,0 , sizeof(cap));
int c;
for(int i=1;i<=n;i++)
{
scanf("%d",&c);
cap[2*i-1][2*i]=c;
for(int j=1;j<=p;j++)
scanf("%d",&in[i][j]);
for(int j=1;j<=p;j++)
scanf("%d",&out[i][j]);
}
N=2*n+1;
for(int i=1;i<=n;i++)
{
if(matchs(in[i]))
{
cap[0][2*i-1]=INF;
// printf("%d %d---\n",0,2*i-1);
}
if(matcht(out[i]))
{
cap[2*i][N]=INF;
// printf("%d %d++++\n",2*i,N);
}
for(int j=1;j<=n;j++)
{
if(match(out[i],in[j]))
{
cap[2*i][2*j-1]=INF;
// printf("%d %d##\n",2*i,2*j-1);
}
}
}
printf("%d ",EK(0,N));
int ans=0;
int x[MAXN],y[MAXN],z[MAXN];
for (int i = 1; i <n; ++i)
{
for(int j=1;j<=n;j++)
{
if(match(out[i],in[j]))
{
if(cap[2*i][2*j-1]!=INF)
{
ans++;
x[ans-1]=i;y[ans-1]=j;z[ans-1]=INF-cap[2*i][2*j-1];
if(z[ans-1]<0)//此处是考虑会把回去的边计算上,我们需要把他去掉。
ans--;
}
}
}
}
printf("%d\n",ans);
for(int i=0;i<ans;i++)
printf("%d %d %d\n",x[i],y[i],z[i]);
}
return 0;
}
POJ3436------ACM Computer Factory的更多相关文章
- POJ3436 ACM Computer Factory —— 最大流
题目链接:https://vjudge.net/problem/POJ-3436 ACM Computer Factory Time Limit: 1000MS Memory Limit: 655 ...
- POJ3436 ACM Computer Factory 【最大流】
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5412 Accepted: 1 ...
- POJ-3436 ACM Computer Factory(网络流EK)
As you know, all the computers used for ACM contests must be identical, so the participants compete ...
- poj3436 ACM Computer Factory, 最大流,输出路径
POJ 3436 ACM Computer Factory 电脑公司生产电脑有N个机器.每一个机器单位时间产量为Qi. 电脑由P个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...
- POJ3436 ACM Computer Factory(最大流/Dinic)题解
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8944 Accepted: 3 ...
- poj-3436.ACM Computer Factory(最大流 + 多源多汇 + 结点容量 + 路径打印 + 流量统计)
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10940 Accepted: ...
- POJ-3436 ACM Computer Factory 最大流 为何拆点
题目链接:https://cn.vjudge.net/problem/POJ-3436 题意 懒得翻,找了个题意. 流水线上有N台机器装电脑,电脑有P个部件,每台机器有三个参数,产量,输入规格,输出规 ...
- POJ3436 ACM Computer Factory(最大流)
题目链接. 分析: 题意很难懂. 大体是这样的:给每个点的具体情况,1.容量 2.进入状态 3.出去状态.求最大流. 因为有很多点,所以如果一个点的出去状态满足另一个点的进入状态,则这两个点可以连一条 ...
- POJ3436 ACM Computer Factory【EK算法】
题意: 每个电脑需要P个组成部分,现有N的机器,每个机器都可以对电脑进行加工,不过加工的前提是某些部分已经存在,加工后会增加某些部分.且在单位时间内,每个机器的加工都有一个最大加工容量,求能得到的最大 ...
- POJ-3436:ACM Computer Factory (Dinic最大流)
题目链接:http://poj.org/problem?id=3436 解题心得: 题目真的是超级复杂,但解出来就是一个网络流,建图稍显复杂.其实提炼出来就是一个工厂n个加工机器,每个机器有一个效率w ...
随机推荐
- MS Chart 条状图【转】
private void Form1_Load(object sender, EventArgs e) { string sql1 = "select 类别,coun ...
- 《Head First 设计模式》之装饰者模式——饮料加工
装饰者模式(Decorator) ——动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更有弹性的替代方案. 特点:建立拥有共同超类的装饰者与被装饰者来实现功能的动态扩展 原则:对扩展开放,对 ...
- Django--对表的操作
一丶多表创建 1.创建模型 实例:我们来假定下面这些概念,字段和关系 作者模型:一个作者有姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息.作者详情模型和作者模型之 ...
- ArcGIS API for Javascript 使用缓冲区结果做query查询出现“esri.config.defaults.io.proxyUrl 尚未进行设置”错误
1.前言 在研究ArcGIS API for JavaScript时会遇到这样的问题,比如我们在做缓冲区分析时,用分析的范围作为空间查询query的参数,在执行结果中总是会看到“esri.config ...
- nmap --script http-enum,http-headers,http-methods,http-php-version -p 80 目标域
从http服务器上收集到更多地信息 nmap --script http-enum,http-headers,http-methods,http-php-version -p 80 目标域
- intellij idea中设置SVN插件教程
1.选择VCS→Browser VCS Repository→Browse Subversion Repository 2.在弹出的SVN Repository菜单中,选择左上角的绿色“+”号,填写S ...
- 更新KB915597补丁后导致“您的windows副本不是正版”的解决方案
更新KB915597补丁后导致“您的windows副本不是正版”的解决方案 解决方法: 运行cw.exe(https://pan.lanzou.com/i05ya8h),直至提示成功: 重新启动操作系 ...
- php之基础深入---类与对象篇
1.类的自动加载: spl_autoload_register()函数可以注册任意数量的自动加载器,当使用尚未被定义的类(class)和接口(interface)时自动去加载,这样可以避免includ ...
- [转载]AngularJS入门教程04:双向绑定
在这一步你会增加一个让用户控制手机列表显示顺序的特性.动态排序可以这样实现,添加一个新的模型属性,把它和迭代器集成起来,然后让数据绑定完成剩下的事情. 请重置工作目录: git checkout -f ...
- hdu-1879 继续畅通工程---确定部分边的MST
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1879 题目大意: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的 ...