http://poj.org/problem?id=1459

也是网络流的基础,只是虚拟出一个源点和终点,对应的生产值和消费值就加到与源点和终点的边上,然后做一次bfs就好了。

 #include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#define INF 999999999
//#define OPEN_FILE
using namespace std; const int MAXN = ;
int cap[MAXN][MAXN], flow[MAXN][MAXN], p[MAXN], c[MAXN], f[MAXN];
int n, ans; void get_cap(char s[])
{
int i, u, v, w;
u = ;
for (i = ; s[i] != ','; i++){
u = u * + (s[i] - '');
}
v = ;
for (++i; s[i] != ')'; i++){
v = v * + (s[i] - '');
}
int len = strlen(s);
w = ;
for (++i; i < len; i++){
w = w * + (s[i] - '');
}
cap[u][v] = w;
} void get_pc(char s[], int* t, int o)
{
int i, u, w;
u = ;
for (i = ; s[i] != ')'; i++){
u = u * + (s[i] - '');
}
int len = strlen(s);
w = ;
for (++i; i < len; i++){
w = w * + (s[i] - '');
}
if (o){
cap[n][u] = w;
}
else{
cap[u][n + ] = w;
} } void ek_bfs(){
queue<int> d;
int s, t, u, v;
int a[MAXN];
s = n;
t = n + ;
ans = ;
while (){
memset(a, , sizeof(a));
a[s] = INF;
d.push(s);
while (!d.empty()){
u = d.front();
d.pop();
for (v = ; v <= n + ; v++){
if (a[v] || cap[u][v] <= flow[u][v]) continue;
f[v] = u;
d.push(v);
a[v] = min(a[u] , cap[u][v] - flow[u][v]);
}
}
if (a[t] == ) break;
for (u = t; u != s; u = f[u]){
flow[f[u]][u] += a[t];
flow[u][f[u]] -= a[t];
}
ans += a[t];
}
} int main()
{
#ifdef OPEN_FILE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int m, np, nc, i, j;
char s[];
while (~scanf("%d%d%d%d", &n, &np, &nc, &m)){
memset(cap, , sizeof(cap));
memset(flow, , sizeof(flow));
memset(p, , sizeof(p));
memset(c, , sizeof(c));
for (i = ; i <= m; i++){
scanf("%s", s);
get_cap(s);
}
for (i = ; i <= np; i++){
scanf("%s", s);
get_pc(s, p, );
}
for (i = ; i <= nc; i++){
scanf("%s", s);
get_pc(s, c, );
}
ek_bfs();
printf("%d\n", ans);
}
}

POJ 1459 最大流 第二题的更多相关文章

  1. poj 1459 (最大流)

    最大流简单题,,这题重要的是知道了scanf("%s",str);sscanf(str,"(%d,%d)%d",&x,&y,&w);读入 ...

  2. POJ 1087 最大流裸题 + map

    A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15597   Accepted: 5308 ...

  3. Power Network - poj 1459 (最大流 Edmonds-Karp算法)

      Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24788   Accepted: 12922 Description A ...

  4. Going Home POJ - 2195 费用流板子题

    On a grid map there are n little men and n houses. In each unit time, every little man can move one ...

  5. POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Network / FZU 1161 (网络流,最大流)

    POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Networ ...

  6. poj 1459 多源多汇点最大流

    Sample Input 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 ...

  7. hdu 3395(KM算法||最小费用最大流(第二种超级巧妙))

    Special Fish Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. 05:统计单词数【NOIP2011复赛普及组第二题】

    05:统计单词数 总时间限制:  1000ms 内存限制:  65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...

  9. hdu Flow Problem (最大流 裸题)

    最大流裸题,贴下模版 view code#include <iostream> #include <cstdio> #include <cstring> #incl ...

随机推荐

  1. 性能测试中的TPS与HPS

    性能测试中的TPS与HPS TPS(Transaction per second) 是估算应用系统性能的重要依据.其意义是应用系统每秒钟处理完成的交易数量.一般的,评价系统性能均以每秒钟完成的技术交易 ...

  2. 紫书 习题8-9 UVa 1613 (dfs染色+图的性质)

    这道题一开始我没想什么直接开始染, 但是是for循环一个节点一个节点染, 然后就WA 后了看了https://www.cnblogs.com/jerryRey/p/4702323.html 发现原来还 ...

  3. Docker安装MySQL忽略大小写问题的问题

    原文:Docker安装MySQL忽略大小写问题的问题 连接MySQL: 查看当前mysql的大小写敏感配置show global variables like '%lower_case%';+---- ...

  4. Adobe Flex迷你教程 —Flex4全屏显示

    应用场景 1.播放器 我们经常看视频的时候,需要全屏显示,(在flex中这个视频初始化的时候是嵌入到html的iframe中). 2.监控 如下图所示,大多时候我们的监控用的是flex,而树形菜单和标 ...

  5. macOS seria 10.12升级到macOS Mojave的报错:xcrun: error: invalid active developer path, missing xcrun

    今天升级mac系统到macOS mojave后,在终端操作gitlab时遇到一行莫名其妙的错误: xcrun: error: invalid active developer path (/Libra ...

  6. debug和release的区别

    Debug和Release,主要是针对其面向的目标不同的而进行区分的.Debug通常称为调试版本,通过一系列编译选项的配合,编译的结果通常包含调试信息,而且不做任何优化,以为开发人员提供强大的应用程序 ...

  7. 洛谷—— P1855 榨取kkksc03

    https://www.luogu.org/problem/show?pid=1855 题目描述 洛谷2的团队功能是其他任何oj和工具难以达到的.借助洛谷强大的服务器资源,任何学校都可以在洛谷上零成本 ...

  8. 洛谷—— P2663 越越的组队

    https://www.luogu.org/problem/show?pid=2663 题目描述 班级要组织一场综合能力竞赛,全班同学(N个,N是偶数)分成两队互相竞争.老师找到了越越并给了越越一张全 ...

  9. Ubuntu 10.04 右上角网络管理图标消失的解决的方法

           那个显示网络状态的那个图标.叫做:network-manager.假设是有线网络连接的话.是上下两个箭头,假设是无线网络的话.是一个发射信号的形状. sudo gedit /etc/Ne ...

  10. Nginx搭建图片服务器

    Nginx搭建图片服务器 标签(空格分隔): linux,nginx Nginx常用命令 ./nginx 启动 ./nginx -s reload 重载配置文件 ./nginx -s stop|sta ...