POJ - 3436 ACM Computer Factory 网络流
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 网络流的更多相关文章
- 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 ACM Computer Factory 题目描述: n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有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 ...
- POJ 3436 ACM Computer Factory 最大流,拆点 难度:1
题目 http://poj.org/problem?id=3436 题意 有一条生产线,生产的产品共有p个(p<=10)零件,生产线上共有n台(n<=50)机器,每台机器可以每小时加工Qi ...
- POJ - 3436 ACM Computer Factory(最大流)
https://vjudge.net/problem/POJ-3436 题目描述: 正如你所知道的,ACM 竞赛中所有竞赛队伍使用的计算机必须是相同的,以保证参赛者在公平的环境下竞争.这就是所有这些 ...
- POJ 3436 ACM Computer Factory(最大流+路径输出)
http://poj.org/problem?id=3436 题意: 每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了.计算机的生产过程通过N台不同的机器来完成,每台机器用它的性 ...
- POJ 3436 ACM Computer Factory (拆点+输出解)
[题意]每台计算机由P个零件组成,工厂里有n台机器,每台机器针对P个零件有不同的输入输出规格,现在给出每台机器每小时的产量,问如何建立流水线(连接各机器)使得每小时生产的计算机最多. 网络流的建图真的 ...
- POJ 3436 ACM Computer Factory
题意: 为了追求ACM比赛的公平性,所有用作ACM比赛的电脑性能是一样的,而ACM董事会专门有一条生产线来生产这样的电脑,随着比赛规模的越来越大,生产线的生产能力不能满足需要,所以说ACM董事会想 ...
- poj 3436 ACM Computer Factory 最大流+记录路径
题目 题意: 每一个机器有一个物品最大工作数量,还有一个对什么物品进行加工,加工后的物品是什么样.给你无限多个初始都是000....的机器,你需要找出来经过这些机器操作后最多有多少成功的机器(111. ...
随机推荐
- 1.4.2python网站地图爬虫(每天一更)
# -*- coding: utf-8 -*- ''' Created on 2019年5月6日 @author: 薛卫卫 ''' import urllib.request import re de ...
- JS面向对象编程(一):封装
js是一门基于面向对象编程的语言. 如果我们要把(属性)和(方法)封装成一个对象,甚至要从原型对象生成一个实例,我们应该怎么做呢? 一.生成对象的原始模式 假定把猫看 ...
- ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core
前言 原本本节内容是不存在的,出于有几个人问到了我:我想使用ASP.NET Core Identity,但是我又不想使用默认生成的数据库表,想自定义一套,我想要使用ASP.NE Core Identi ...
- Selenium+java - 调用JavaScript操作
前言 在做web自动化时,有些情况selenium的api无法完成,需要通过第三方手段比如js来完成实现,比如去改变某些元素对象的属性或者进行一些特殊的操作,本文将来讲解怎样来调用JavaScript ...
- 定时器任务django-crontab的使用【静态化高频率页面,增加用户体验】【系统的定时器,独立于项目执行】【刘新宇】
页面静态化 思考: 网页的首页访问频繁,而且查询数据量大,其中还有大量的循环处理. 问题: 用户访问首页会耗费服务器大量的资源,并且响应数据的效率会大大降低. 解决: 页面静态化 1. 页面静态化介绍 ...
- 记一次mysql主从同步因断电产生的不能同步问题 1236 1032
背景: 项目新上线一个月,qa需要测试断电服务拉起,服务拉起成功后,发现mysql主从异常,以下是发现的问题以及解决方案 问题1: Slave_IO_Running: No 一方面原因是因为网络通信 ...
- IntelliJ IDEA 激活(最新)
注:此文以 Mac 为例,Windows 的激活方法也大同小异.如果不差钱的话,建议购买正版! 1.下载安装 直接通过下面的链接到官网下载最新的 Ultimate 版本即可: https://www. ...
- 7.15 迭代器 for循环的本质 生成器
迭代器 迭代:更新换代的过程,每次的迭代都必须基于上一次的结果 迭代器:迭代取值的工具 作用 迭代器提供了一种不依赖于索引取值的方式 根据以上对于迭代的描述,如果只是简单的重复,不算迭代,如下: n ...
- django在启动时抛出Error: [WinError 10013] 以一种访问权限不允许的方式做了一个访问套接字的尝试 解决办法
1.适用场景 在启动某个服务的时候,比如python中django启动的时候8000端口被占用,导致无法启动服务. 2.解决办法 通过命令行找出端口对应的PID进程 C:\Users\micha> ...
- 100天搞定机器学习|day43 几张GIF理解K-均值聚类原理
前文推荐 如何正确使用「K均值聚类」? KMeans算法是典型的基于距离的聚类算法,采用距离作为相似性的评价指标,即认为两个对象的距离越近,其相似度就越大.该算法认为簇是由距离靠近的对象组成的,因此把 ...