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

题意

  组配计算机,每个机器的能力为x,只能处理一定条件的计算机,能输出特定的计算机配置。进去的要求有1,进来的计算机这个位子就要求为1,进去的要求有0,进来的计算机这个位子就要求为0.

思路

因为点上有容量限制,所以把每个点拆掉,连一条容量为这个机器的能力的边。源点向要求为0的机器连容量inf的边,把能完全组装好计算机的机器连向汇点。中间把符合条件的机器间连边,容量为inf;

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cctype>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int ,pii> p3;
//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFFLL; //
const ll nmos = 0x80000000LL; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
const int maxn = ;
int p,n;
struct node{
int d;
int in[maxn],out[maxn];
}a[maxn]; struct edge
{
int u,v,cap;
edge(){}
edge(int u,int v,int cap):
u(u),v(v),cap(cap){}
}es[];
int tot,s,t;
vector<int>tab[];
int dis[],cur[];
void addedge(int u,int v,int cap){
tab[u].pb(tot);
es[tot++] = edge(u,v,cap);
tab[v].pb(tot);
es[tot++] = edge(v,u,);
} bool bfs(){
queue<int>q;q.push(s);
memset(dis,inf,sizeof(dis));
dis[s] = ;
while(!q.empty()){
int h = q.front();q.pop();
for(int i=; i<tab[h].size(); i++){
edge &e = es[tab[h][i]];
if(e.cap > && dis[e.v] >= inf){
dis[e.v] = dis[h] + ;
q.push(e.v);
}
}
}
return dis[t] < inf;
}
int dfs(int x,int maxflow){
if(x==t)return maxflow;
for(int i=cur[x] ; i<tab[x].size(); i++){
cur[x] = i;
edge &e = es[tab[x][i]];
if(dis[e.v] == dis[x] + && e.cap > ){
int flow = dfs(e.v, min(maxflow, e.cap));
if(flow){
e.cap -= flow;
es[tab[x][i] ^ ].cap += flow;
return flow;
}
}
}
return ;
}
int dinic(){
int ans = ; while(bfs()){
int flow;
memset(cur,,sizeof(cur));
do{
flow = dfs(s,inf);
if(flow)ans += flow;
}while(flow);
}
return ans;
}
int main(){
scanf("%d%d", &p, &n);
for(int i=; i<=n; i++){
scanf("%d", &a[i].d);
addedge(i,i+n,a[i].d);
int t1 = ,t2 = ;
for(int j=; j<=p; j++)scanf("%d",&a[i].in[j]), t1 += a[i].in[j]== ? :;
for(int j=; j<=p; j++)scanf("%d",&a[i].out[j]),t2 += a[i].out[j]>? : ;
if(t1 == ) addedge(, i, inf);
if(t2 == p) addedge(i+n,n+n+,inf);
}
for(int i=; i<=n; i++){
for(int j=; j<=n; j++){
if(i == j)continue;
int flag = ;
for(int t = ; t <= p; t++){
if(a[j].in[t] == && a[i].out[t] == )
flag = ;
if(a[j].in[t] == && a[i].out[t] == )
flag = ;
}
if(flag)addedge(i+n,j,inf);
}
}
s = ,t = n+n+;
printf("%d ", dinic());
int rere = ;
vector<p3>v;
for(int i=; i<=n; i++){
for(int j = ; j < tab[i+n].size(); j++){
edge e = es[tab[i+n][j]];
if(e.cap < inf && i!= e.v&&e.v != t){
//printf("%d %d %d\n",i,e.v,inf - e.cap);
v.pb(p3(i,pii(e.v,inf - e.cap)));
rere ++;
}
}
}
printf("%d\n", rere);
for(int i=; i<rere; i++){
printf("%d %d %d\n", v[i].fi,v[i].se.fi,v[i].se.se);
}
return ;
}

POJ 3436

POJ - 3436 ACM Computer Factory 网络流的更多相关文章

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

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

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

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

  3. 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 ...

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

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

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

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

  6. POJ 3436 ACM Computer Factory(最大流+路径输出)

    http://poj.org/problem?id=3436 题意: 每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了.计算机的生产过程通过N台不同的机器来完成,每台机器用它的性 ...

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

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

  8. POJ 3436 ACM Computer Factory

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

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

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

随机推荐

  1. R语言学习笔记——C#中如何使用R语言setwd()函数

    在R语言编译器中,设置当前工作文件夹可以用setwd()函数. > setwd("e://桌面//")> setwd("e:\桌面\")> s ...

  2. HTTP文件上传原理

    前言 对于这块知识点,我一直都是模糊的,不是非常清楚的.在平时的工作中,遇到上传的问题,也没有深入的去研究过,也都是直接用别人封装好的类来完成自己的工作.某一天,看了本书,说到这个知识点,一脸茫然,觉 ...

  3. CSS3 filter 模糊滤镜的应用

    CSS3 filter 模糊滤镜的应用   在segmentfault上回答过的一个问题,如何将网页CSS背景图高斯模糊且全屏显示当时没有深入了解,只觉得滤镜应该只是应用于图片上的.而且各大网站的de ...

  4. 【Java例题】5.3 线性表的使用

    3.线性表的使用.使用ArrayList模拟一个一维整数数组.数据由Random类随机产生.进行对输入的一个整数进行顺序查找.并进行冒泡排序. package chapter6; import jav ...

  5. Spring cloud 超时配置总结

    基准配置: eureka-server : 注册中心 端口号1000 service-A : 服务A端口号2000 service-B : 服务B 端口号3000 其中,B服务通过feign调用服务A ...

  6. 统计学习方法—SVM推导

    目录 SVM 1. 定义 1.1 函数间隔和几何间隔 1.2 间隔最大化 2. 线性可分SVM 2.1 对偶问题 2.2 序列最小最优算法(SMO) 3. 线性不可分SVM 3.1 松弛变量 3.2 ...

  7. HBuilderX使用Vant组件库

    HBuilderX使用Vant组件库 HBuilderX是一款由国人开发的开发工具,其官网称其为轻如编辑器.强如IDE的合体版本.但是官方的社区中关于Vant组件的安装大多都是针对微信小程序开发安装V ...

  8. struts与springmvc有何区别

    Struts2与SpringMVC有何区别? (1)SpringMVC的核心控制器是基于servlet技术,而Struts2是基于filter. (2)Struts2是类级别的拦截, 一个类对应一个r ...

  9. django报错信息解决方法

    You have 17 unapplied migration(s). Your project may not work properly until you apply the migration ...

  10. 7.19 包 logging模块 hashlib模块 openpyxl模块 深浅拷贝

    包 包是什么 他是一系列文件的结合体,表现形式就是文件夹 包的本质还是模块 他通常会有__init__.py文件 我们首先回顾一下模块导入的过程 import module首次导入模块(.py文件) ...