http://poj.org/problem?id=3436

题意:

每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了。计算机的生产过程通过N台不同的机器来完成,每台机器用它的性能(每小时组装多少台电脑)、输入/输出规格来描述。

输入规格描述了机器在组装计算机时哪些部件必须准备好了。输入规格是由P个整数组成,每个整数代表一个部件,这些整数取值为0、1或2,其中0表示该部件不应该已经准备好了,1表示该部件必须已经准备好了,2表示该部件是否已经准备好了无关紧要。

输出规格描述了该机器组装的结果。输出规格也是由P个整数组成,每个整数取值 为0或1,其中0代表该部件没有生产好,1代表该部件生产好了。

输出每单位时间内的最大产量和连接数量和路径。

思路:
因为每台机器都有一个产量,所以这里拆点,容量为机器的产量。

对每台机器进行检验,如果它的要求中不包含1,那么它就和源点相连,说明这台机器是可以最先开始组装电脑的,如果它的输出中全是1,说明这台机器已经把电脑组装好了,和汇点相连。

然后机器之间两两判断,是否可以相连。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; struct Edge
{
int from,to,cap,flow;
Edge(int u,int v,int w,int f):from(u),to(v),cap(w),flow(f){}
}; struct Dinic
{
int n,m,s,t;
vector<Edge> edges;
vector<int> G[maxn];
bool vis[maxn];
int cur[maxn];
int d[maxn]; void init(int n)
{
this->n=n;
for(int i=;i<n;++i) G[i].clear();
edges.clear();
} void AddEdge(int from,int to,int cap)
{
edges.push_back( Edge(from,to,cap,) );
edges.push_back( Edge(to,from,,) );
m=edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool BFS()
{
queue<int> Q;
memset(vis,,sizeof(vis));
vis[s]=true;
d[s]=;
Q.push(s);
while(!Q.empty())
{
int x=Q.front(); Q.pop();
for(int i=;i<G[x].size();++i)
{
Edge& e=edges[G[x][i]];
if(!vis[e.to] && e.cap>e.flow)
{
vis[e.to]=true;
d[e.to]=d[x]+;
Q.push(e.to);
}
}
}
return vis[t];
} int DFS(int x,int a)
{
if(x==t || a==) return a;
int flow=, f;
for(int &i=cur[x];i<G[x].size();++i)
{
Edge &e=edges[G[x][i]];
if(d[e.to]==d[x]+ && (f=DFS(e.to,min(a,e.cap-e.flow) ) )>)
{
e.flow +=f;
edges[G[x][i]^].flow -=f;
flow +=f;
a -=f;
if(a==) break;
}
}
return flow;
} int Maxflow(int s,int t)
{
this->s=s; this->t=t;
int flow=;
while(BFS())
{
memset(cur,,sizeof(cur));
flow +=DFS(s,INF);
}
return flow;
}
}DC; int p,n;
int w[maxn];
int s[maxn][maxn];
int d[maxn][maxn]; bool isStart(int x)
{
for(int i=;i<=p;i++)
if(s[x][i]==) return false;
return true;
} bool isEnd(int x)
{
for(int i=;i<=p;i++)
{
if(d[x][i]==) return false;
}
return true;
} bool connect(int x, int y)
{
for(int i=;i<=p;i++)
{
if((s[y][i]== && d[x][i]==) ||(s[y][i]== && d[x][i]==)) return false;
}
return true;
} int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d",&p,&n))
{
int src=, dst=*n+;
DC.init(dst+); for(int i=;i<=n;i++)
{
scanf("%d",&w[i]); for(int j=;j<=p;j++)
scanf("%d",&s[i][j]);
for(int j=;j<=p;j++)
scanf("%d",&d[i][j]); if(isStart(i)) DC.AddEdge(src,i,INF);
if(isEnd(i)) DC.AddEdge(i+n,dst,INF);
} for(int i=;i<=n;i++) DC.AddEdge(i,i+n,w[i]); for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(i==j) continue;
if(connect(i,j)) DC.AddEdge(i+n,j,INF);
}
} int ans=DC.Maxflow(src,dst); int cnt=;
for(int i=;i<DC.edges.size();i++)
{
Edge& e=DC.edges[i];
if(e.from==src || e.from==dst || e.to==src || e.to==dst) continue;
if((e.from+n)==e.to||(e.from-n)==e.to) continue;
if(e.flow<) cnt++;
}
printf("%d %d\n",ans,cnt); for(int i=;i<DC.edges.size();i++)
{
Edge& e=DC.edges[i];
if(e.from==src || e.from==dst || e.to==src || e.to==dst) continue;
if((e.from+n)==e.to||(e.from-n)==e.to) continue;
if(e.flow<)
printf("%d %d %d\n",e.to-n,e.from,-e.flow);
}
}
return ;
}

POJ 3436 ACM Computer Factory(最大流+路径输出)的更多相关文章

  1. Poj 3436 ACM Computer Factory (最大流)

    题目链接: Poj 3436 ACM Computer Factory 题目描述: n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑? 解题 ...

  2. poj 3436 ACM Computer Factory 最大流+记录路径

    题目 题意: 每一个机器有一个物品最大工作数量,还有一个对什么物品进行加工,加工后的物品是什么样.给你无限多个初始都是000....的机器,你需要找出来经过这些机器操作后最多有多少成功的机器(111. ...

  3. POJ 3436 ACM Computer Factory 最大流,拆点 难度:1

    题目 http://poj.org/problem?id=3436 题意 有一条生产线,生产的产品共有p个(p<=10)零件,生产线上共有n台(n<=50)机器,每台机器可以每小时加工Qi ...

  4. POJ 3436 ACM Computer Factory (网络流,最大流)

    POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...

  5. POJ - 3436 ACM Computer Factory 网络流

    POJ-3436:http://poj.org/problem?id=3436 题意 组配计算机,每个机器的能力为x,只能处理一定条件的计算机,能输出特定的计算机配置.进去的要求有1,进来的计算机这个 ...

  6. POJ - 3436 ACM Computer Factory(最大流)

    https://vjudge.net/problem/POJ-3436 题目描述:  正如你所知道的,ACM 竞赛中所有竞赛队伍使用的计算机必须是相同的,以保证参赛者在公平的环境下竞争.这就是所有这些 ...

  7. POJ 3436 ACM Computer Factory

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

  8. POJ 3436 ACM Computer Factory (拆点+输出解)

    [题意]每台计算机由P个零件组成,工厂里有n台机器,每台机器针对P个零件有不同的输入输出规格,现在给出每台机器每小时的产量,问如何建立流水线(连接各机器)使得每小时生产的计算机最多. 网络流的建图真的 ...

  9. kuangbin专题专题十一 网络流 POJ 3436 ACM Computer Factory

    题目链接:https://vjudge.net/problem/POJ-3436 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. IIS 无法访问.net的动态文件

    编译器错误消息:CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319... 在“c:\windows\temp”这个文件夹添 ...

  2. Xcode - 插件管理工具Alcatraz

    Alcatraz 1.简介 Alcatraz是一个能帮你管理Xcode插件丶模版及颜色配置的工具.它可以直接集成在Xcode的图形界面中,让你感觉就像在使用Xcode自带的功能一样. 2.安装和删除 ...

  3. Hive JOIN使用详解

    转自http://shiyanjun.cn/archives/588.html Hive是基于Hadoop平台的,它提供了类似SQL一样的查询语言HQL.有了Hive,如果使用过SQL语言,并且不理解 ...

  4. aliyun oss 文件上传 java.net.SocketTimeoutException Read timed out 问题分析及解决

    upload ClientException Read timed out com.aliyun.openservices.ClientException: Read timed out        ...

  5. Docker企业级仓库Harbor的安装配置与使用

    Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全.标识和管理等,扩展了开源Docker Distribution.作为一个企业级 ...

  6. 向Docx4j生成的word文档中添加布局--第二部分

    原文标题:Adding layout to your Docx4j-generated word documents, part 2 原文链接:http://blog.iprofs.nl/2012/1 ...

  7. Intellij idea的Dependencies波浪线

    昨天在家做项目不知道搞了什么出现了大量波浪线.搞了大半天解决了下面的问题. 1.pom.xml出现波浪线.看右边 maven project-->Profiles 勾选dev 2.上面已勾选还有 ...

  8. UVA 624 ---CD 01背包路径输出

    DescriptionCD You have a long drive by car ahead. You have a tape recorder, but unfortunately your b ...

  9. 设置UCHome注册登陆退出的跳转页自定义

    UCHome 默认注册.登录成功后跳转到 http://www.xxx.com/home/space.php?do=home 退出后会跳转到站点的首页,即 http://www.xxx.com/hom ...

  10. ASP.Net Core 使用Redis实现分布式缓存

    本篇我们记录的内容是怎么在Core中使用Redis 和 SQL Server 实现分布式缓存. 一.文章概念描述   分布式缓存描述: 分布式缓存重点是在分布式上,相信大家接触过的分布式有很多中,像分 ...