POJ 3436 ACM Computer Factory(最大流+路径输出)
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(最大流+路径输出)的更多相关文章
- Poj 3436 ACM Computer Factory (最大流)
题目链接: Poj 3436 ACM Computer Factory 题目描述: n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑? 解题 ...
- poj 3436 ACM Computer Factory 最大流+记录路径
题目 题意: 每一个机器有一个物品最大工作数量,还有一个对什么物品进行加工,加工后的物品是什么样.给你无限多个初始都是000....的机器,你需要找出来经过这些机器操作后最多有多少成功的机器(111. ...
- POJ 3436 ACM Computer Factory 最大流,拆点 难度:1
题目 http://poj.org/problem?id=3436 题意 有一条生产线,生产的产品共有p个(p<=10)零件,生产线上共有n台(n<=50)机器,每台机器可以每小时加工Qi ...
- POJ 3436 ACM Computer Factory (网络流,最大流)
POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...
- POJ - 3436 ACM Computer Factory 网络流
POJ-3436:http://poj.org/problem?id=3436 题意 组配计算机,每个机器的能力为x,只能处理一定条件的计算机,能输出特定的计算机配置.进去的要求有1,进来的计算机这个 ...
- POJ - 3436 ACM Computer Factory(最大流)
https://vjudge.net/problem/POJ-3436 题目描述: 正如你所知道的,ACM 竞赛中所有竞赛队伍使用的计算机必须是相同的,以保证参赛者在公平的环境下竞争.这就是所有这些 ...
- POJ 3436 ACM Computer Factory
题意: 为了追求ACM比赛的公平性,所有用作ACM比赛的电脑性能是一样的,而ACM董事会专门有一条生产线来生产这样的电脑,随着比赛规模的越来越大,生产线的生产能力不能满足需要,所以说ACM董事会想 ...
- POJ 3436 ACM Computer Factory (拆点+输出解)
[题意]每台计算机由P个零件组成,工厂里有n台机器,每台机器针对P个零件有不同的输入输出规格,现在给出每台机器每小时的产量,问如何建立流水线(连接各机器)使得每小时生产的计算机最多. 网络流的建图真的 ...
- 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 ...
随机推荐
- Python语音合成
注意:通过win32com调用的windows的SAPI,所以本脚本只适应于windows平台 代码很简单 #coding:utf-8 import win32com.client import ti ...
- 问答项目---账号密码异步校验后进行PHP校验
在做登陆的时候,通过异步校验后还需要通过PHP来校验账号和密码的正确性. PHP校验账号密码: public function login(){ if(!IS_POST){echo "页面不 ...
- kmp的next数组的运用(求字符串的最小循环节)
hdu3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- 网络流SAP+gap+弧优化算法
poj1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54962 Accept ...
- localstorage - HTML 5 Web 存储总结---【巷子】
001.localStorage概念 在html5中,新加入了一个localStorage特性,这个特性主要是用来作为本地存储,解决了cookie存储空间不足的问题(cookie中每条cookie存储 ...
- sql_q.format
field_q_insert = 'id, title, number, created,content'sql_q = 'INSERT INTO testquestion ({}) VALUES ( ...
- nginx ---refine---按需时间/流量进行调整后台服务器---geocity,proxypass
原理相当于配置文件在启动时进行编译,proxyPass http://mydomain/path/xxxx这种方式是编译成静态的,直接替换成它解析到的ip/vip,只有重新启动时才会重新解析. 而 s ...
- 如何打造高性能Web应用
Sean Hull是Heavyweight Internet Group的创始人兼高级顾问,拥有20年以上技术顾问相关经验,曾为多家知名机构提供咨询,其中包括The Hollywood Reporte ...
- 内核通信之Netlink源码分析-用户内核通信原理3
2017-07-06 上节主讲了用户层通过netlink和内核交互的详细过程,本节分析下用户层接收数据的过程…… 有了之前基础知识的介绍,用户层接收数据只涉及到一个核心调用readmsg(), 其他的 ...
- YOGA Tablet 2 1371f 触屏失效,无声卡,蓝牙键盘都无法使用的解决办法
安装驱动! 下载地址 http://www.lenovocare.com.cn/Handler/Download.ashx?fileid=1234 安装后电源管理,声卡,触摸屏即可使用! 蓝牙键盘连接 ...