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. 游戏开发3D基础知识

    概念学习: 向量 向量简介 我们将所有彼此平行的向量进行平移,使其起点与坐标原点重合,当某一向量的起始端与坐标原点重合,我们成该向量处于标准位置.这样,我们就可用向量的终点坐标来描述一个处于标准位置的 ...

  2. 【iOS】Ineligible Devices || “无法下载应用程序”

    今天遇到了这个问题,Xcode 显示如图所示: 还有真机测试无法安装的问题,如图: 究其原因,都是 版本不匹配 的问题!在 Xcode 中的 PROJECT 和 TARGETS 设置下版本就行了,如下 ...

  3. java的jar打包工具的使用

    java的jar打包工具的使用 java的jar是一个打包工具,用于将我们编译后的class文件打包起来,这里面主要是举一个例子用来说明这个工具的使用. 在C盘下的temp文件夹下面:         ...

  4. 深入理解JVM-类加载器深入解析(2)

    深入理解JVM-类加载器深入解析(2) 加载:就是把二进制形式的java类型读入java虚拟机中 连接: 验证: 准备:为类变量分配内存,设置默认值.但是在到达初始化之前,类变量都没有初始化为真正的初 ...

  5. 开启java之门

    一.Java语言概述 Java语言诞生于1995年,由Sun公司推出. 2009年,Sun公司被甲骨文公司收购,所以我们现在访问oracle官网即可:https://www.oracle.com Ja ...

  6. Java的几种常见排序算法

    一.所谓排序,就是使一串记录,按照其中的某个或某些关键字的大小,递增或递减的排列起来的操作.排序算法,就是如何使得记录按照要求排列的方法.排序算法在很多领域得到相当地重视,尤其是在大量数据的处理方面. ...

  7. Java线程池的增长过程

    通过ThreadPoolExecutor的方式创建线程池 ThreadPoolExecutor 构造方法: public ThreadPoolExecutor(int corePoolSize, in ...

  8. centos7安装mongodb详解

    记录一下linux下安装mongodb数据库过程. 安装mongodb #下载linux版本的tar文件#  例如笔者下载的是:mongodb-linux-x86_64-rhel70-3.4.4.tg ...

  9. Resource 使用详解

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  10. Flask+APScheduler定时任务

    1.安装依赖 pip install flask_apscheduler 2.使用定时任务 ```python from flask import Flask from flask_apschedul ...