题目链接:

  Poj 3436 ACM Computer Factory

题目描述:

  n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑?

解题思路:

  因为需要输出流水线要经过的工厂路径,如果要用电脑状态当做节点的话,就GG了。所以建图的时候要把工厂当做节点。对于节点i,能生产si电脑的节点可以进入节点i,能转化ei电脑的节点可以由i节点进入。要注意对于每一个节点要进行拆点,防止流量发生错误。

 #include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f3f;
struct node
{
int x, s[], e[];
} mach[maxn];
struct node1
{
int s, e, x;
} path[maxn*maxn];
int maps[maxn*][maxn*], Maps[maxn*][maxn*];
int Layer[maxn*], p, n, num; void buildmaps (int s, int e)
{
for (int i=s; i<=e; i++)
{
int j, k;
for (int j=s; j<=e; j++)
{
if (i == j)
continue;
for (k=; k<p; k++)
{
if (mach[i].e[k]== || mach[j].s[k]==)
continue;
if (mach[i].e[k] != mach[j].s[k])
break;
}
if (k == p)
{
if (i > )
Maps[i+n][j] = mach[i].x;
else
Maps[i][j] = mach[i].x;
}
}
} for (int i=; i<=num; i++)
for (int j=; j<=num; j++)
maps[i][j] = Maps[i][j];
} bool CountLayer (int s, int e)
{
queue <int> Q;
memset (Layer, , sizeof(Layer));
Layer[s] = ;
Q.push (s); while (!Q.empty ())
{ int u = Q.front();
Q.pop(); for (int i=; i<=num; i++)
if (!Layer[i] && maps[u][i])
{
Layer[i] = Layer[u] + ;
Q.push (i);
if (i == e)
return true;
}
}
return false;
} int Dfs (int u, int e, int maxflow)
{
if (u == e)
return maxflow; int uflow = ;
for (int i=; i<=num; i++)
{
if (maps[u][i] && Layer[i]==Layer[u]+)
{
int flow = min(maps[u][i], maxflow - uflow);
flow = Dfs (i, e, flow); uflow += flow;
maps[u][i] -= flow;
maps[i][u] += flow;
if (uflow == maxflow)
break;
}
} if (uflow == )
Layer[u] = ; return uflow;
} int Dinic (int s, int e)
{
int maxflow = ; while (CountLayer(s, e))
maxflow += Dfs(s, e, INF); return maxflow;
} int main ()
{
while (scanf ("%d %d", &p, &n) != EOF)
{
memset (mach, , sizeof(mach));
memset (Maps, , sizeof(Maps));
mach[].x = INF;
for (int i=; i<p; i++)
{
mach[].s[i] = INF;
mach[].e[i] = INF;
mach[].s[i] = ;
} for (int i=; i<n+; i++)
{
scanf ("%d", &mach[i].x);
for (int j=; j<p; j++)
scanf ("%d", &mach[i].s[j]);
for (int j=; j<p; j++)
scanf ("%d", &mach[i].e[j]);
Maps[i][i+n] = mach[i].x;//拆点
} int ans, res;
res = ;
num = n + n + ; buildmaps (, n+);
ans = Dinic (, ); for (int i=; i<num; i++)
{
for (int j=; j<num; j++)
{ if (i == j+n || j==i+n)
continue; if (Maps[i][j] - maps[i][j] > )
{
path[res].x = Maps[i][j] - maps[i][j];
path[res].s = (i - ) % n + ;
path[res++].e = (j - ) % n + ;
} }
} printf ("%d %d\n", ans, res);
for (int i=; i<res; i++)
printf ("%d %d %d\n", path[i].s, path[i].e, path[i].x); }
return ;
}

Poj 3436 ACM Computer Factory (最大流)的更多相关文章

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

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

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

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

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

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

  4. POJ - 3436 ACM Computer Factory 网络流

    POJ-3436:http://poj.org/problem?id=3436 题意 组配计算机,每个机器的能力为x,只能处理一定条件的计算机,能输出特定的计算机配置.进去的要求有1,进来的计算机这个 ...

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

随机推荐

  1. linux的bc命令介绍

    bc命令是一种支持任意精度的交互执行的计算器语言.bash内置了对整数四则运算的支持,但是并不支持浮点运算,而bc命令可以很方便的进行浮点运算,当然整数运算也不再话下. 算术操作高级运算bc命令它可以 ...

  2. curl 发送post请求

    curl 发送post请求 curl -X POST "http://localhost:8080/usr3?id=1&name=3&departmentId=2" ...

  3. HDU 5285 wyh2000 and pupil(dfs或种类并查集)

    wyh2000 and pupil Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Other ...

  4. Mongodb for PHP教程之入门安装

    简介: MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据 ...

  5. graph driver-device mapper-03thin pool基本操作

    // 在thin pool中创建一个新thin device // 调用路径:driver.Create() 1.1 func (devices *DeviceSet) AddDevice(hash, ...

  6. Redis入门教程(二)— 基本数据类型

    阅读以下内容时,手边打开一个redis-cli一起输入,输入命令敲击回车键前在心中想好你的答案,如果结果不合你的预期,请分析原因,使极大地提高学习效率.如果没有条件,每个数据类型后有代码运行结果,供你 ...

  7. POJ之01背包系列

    poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<iostream> using na ...

  8. 必备java参考资源列表

    现在开始正式介绍这些参考资源. Web 站点和开发人员 Web 门户 网络无疑改变了共享资源和出版的本质(对我也是一样:您正在网络上阅读这篇文章),因此,从每位 Java 开发人员都应该关注的关键 W ...

  9. Poi 操作 Excel

    http://blog.csdn.net/chenglc1612/article/details/53413445   一. POI简介              Apache POI是Apache软 ...

  10. YTU 1098: The 3n + 1 problem

    1098: The 3n + 1 problem 时间限制: 1 Sec  内存限制: 64 MB 提交: 368  解决: 148 题目描述 Consider the following algor ...