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. 1.4.3 ID遍历爬虫(每天一更)

    # -*- coding: utf-8 -*- ''' Created on 2019年5月7日 @author: 薛卫卫 ''' import itertools import urllib.req ...

  2. 【Android】Fresco 初次使用遇到的坑

    初次使用开源框架 Fresco,结果遇到了坑,被虐了半下午--暂且记下. 下面的错误 android.view.InflateException: Binary XML file line #** 报 ...

  3. 小白学python-day08-文件及其操作、字符串字典类型转换

    今天是day08,以下是学习总结: 但行努力,莫问前程. ----------------------------------------------------------------------- ...

  4. 【Python-Django】Jinja2模板引擎配置教程详解!!!!

    Jinjia2的官方文档:http://jinja.pocoo.org/docs/2.10/ 1. 安装Jinja2扩展包 $ pip install Jinja2 2. 配置Jinja2模板引擎 T ...

  5. swift 分享share页面封装(功能按钮不同)

    关于分享功能的页面应该有很多,写这篇swift版本的分享页面,根据不同模块可能分享的功能按钮不一样,引言: 想必大家都使用微博右上角更多按钮,会弹出如下的界面: 在开发中,可能针对同一个app的不同按 ...

  6. 如何思考博弈dp

    两个人的规则是否一致 若仅仅是先后的差别 我们可用dp解决一般思考一个子状态 对于当前的那个状态 我们进行什么样的操作 已知什么

  7. scrapy框架与python爬虫

  8. java 遍历map的四种方法

    16:21:42 Map.entrySet() 这个方法返回的是一个Set<Map.Entry<K,V>>,Map.Entry 是Map中的一个接口,他的用途是表示一个映射项( ...

  9. 完整原型链详细图解之JS构造函数、原型 原型链、实例化对象

    一.首先说一下什么是构造函数: 构造函数:用来在创建对象时初始化对象.特点:构造函数名一般为大写字母开头:与new运算符一起使用来实例化对象. 举例: function Person(){} //Pe ...

  10. org.apache.spark.logging类报错

    一,1 在使用spark读取kafka数据时,当spark升级到2.0之后,出现如上问题:之前遇到了,当时在工程里面添加了org.apache.spark.Logging类,能够运行. 但是在后期使用 ...