F - Power Network - poj 1459(简单最大流)

分析:懂了题意就是一个模板。。。还不用拆点什么的,不过输入的时候不太明白为什么scanf("(%d,%d)%d")这种输入不好使了,只得用字符串直接读的。
#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<algorithm>
#include<math.h>
using namespace std; const int MAXN = ;
const int oo = 1e9+; int G[MAXN][MAXN], layer[MAXN]; void In(char s[])
{
scanf("%s", s); for(int i=; s[i]; i++)
{
if(s[i]==',' || s[i]=='(' || s[i]==')')
s[i] = ' ';
}
} bool bfs(int start, int End)
{
int used[MAXN] = {};
queue<int> Q;Q.push(start); memset(layer, , sizeof(layer));
used[start] = layer[start] = ; while(Q.size())
{
int u = Q.front();Q.pop(); if(u == End)return true; for(int i=; i<=End; i++)
{
if(!used[i] && G[u][i])
{
used[i] = true;
layer[i] = layer[u] + ;
Q.push(i);
}
}
} return false;
}
int dfs(int u, int MaxFlow, int End)
{
if(u == End)return MaxFlow; int uFlow = ; for(int i=; i<=End; i++)
{
if(G[u][i] && layer[u] == layer[i]-)
{
int flow = min(MaxFlow-uFlow, G[u][i]);
flow = dfs(i, flow, End);
G[u][i] -= flow;
G[i][u] += flow;
uFlow += flow; if(uFlow == MaxFlow)
break;
}
} return uFlow;
}
int dinic(int start, int End)
{
int MaxFlow = ; while(bfs(start, End) == true)
MaxFlow += dfs(start, oo, End); return MaxFlow;
} int main()
{
int N, NP, NC, M; while(scanf("%d%d%d%d", &N, &NP, &NC, &M) != EOF)
{
int i, u, v, flow, start=N, End=start+;
char s[]; memset(G, , sizeof(G)); while(M--)
{///线路
In(s);
sscanf(s, "%d%d%d", &u, &v, &flow); G[u][v] += flow;
} for(i=; i<=NP; i++)
{///输入发电站,与源点相连
In(s);
sscanf(s, "%d%d", &u, &flow);
G[start][u] = flow;
}
for(i=; i<=NC; i++)
{///消费点,与汇点相连
In(s);
sscanf(s, "%d%d", &u, &flow);
G[u][End] = flow;
} printf("%d\n", dinic(start, End));
} return ;
}
F - Power Network - poj 1459(简单最大流)的更多相关文章
- F - Power Network POJ - 1459
题目链接:https://vjudge.net/contest/299467#problem/F 这个是一个很简单的题目,但是读入很有意思,通过这个题目,我学会了一种新的读入方式. 一个旧的是(%d, ...
- Power Network - poj 1459 (最大流 Edmonds-Karp算法)
Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24788 Accepted: 12922 Description A ...
- Power Network (poj 1459 网络流)
Language: Default Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 23407 ...
- Power Network POJ - 1459 [网络流模板]
http://poj.org/problem?id=1459 嗯,网络流模板...多源点多汇点的图,超级汇点连发电厂,用户连接超级汇点 Status Accepted Time 391ms Memor ...
- Power Network POJ - 1459 网络流 DInic 模板
#include<cstring> #include<cstdio> #define FOR(i,f_start,f_end) for(int i=f_startl;i< ...
- Poj(1459),最大流,EK算法
题目链接:http://poj.org/problem?id=1459 Power Network Time Limit: 2000MS Memory Limit: 32768K Total Su ...
- POJ 2135 简单费用流
题意: 题意是一个人他要从牧场1走到牧场n然后在走回来,每条路径只走一次,问全程的最短路径是多少. 思路: 这个题目挺简单的吧,首先要保证每条边只能走一次,然后还要要求费用最 ...
- 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 ...
- 2018.07.06 POJ 1459 Power Network(多源多汇最大流)
Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...
随机推荐
- Interpreter Expression 解释器模式
简介 Interpreter模式也叫解释器模式,是由GoF提出的23种设计模式中的一种.Interpreter是行为模式之一,它是一种特殊的设计模式,它建立一个解释器,对于特定的计算机程序设计语言,用 ...
- NPOI从数据库中导出数据到Excel
首先要添加NPOI.dll程序集 https://yunpan.cn/cMeSTELJSXmJJ 访问密码 8d83 把里面的程序集都添加到引用里 下面的代码是从数据库导出到Excel { //pa ...
- JY03-HTML/CSS-京东02
---恢复内容开始--- 1. position:absolute 1.1 绝对定位设置定位值为百分比时: 如设置right:50%,即元素右侧外边框距离父盒子右侧始终始终为父盒子宽度的一半. 可以使 ...
- 经验分享:CSS浮动(float,clear)通俗讲解(转载)
很早以前就接触过CSS,但对于浮动始终非常迷惑,可能是自身理解能力差,也可能是没能遇到一篇通俗的教程. 前些天小菜终于搞懂了浮动的基本原理,迫不及待的分享给大家. 写在前面的话: 由于CSS内容比较多 ...
- Oracle数据表恢复
用于直接drop掉表的情况(plsql developer直接删掉表就是drop操作) 查删除的表select object_name,original_name,partition_name,typ ...
- My.Ioc 代码示例——Lifetime 和 ILifetimeScope
很多 Ioc 框架在创建对象的过程中,都会采取某种方式来缓存/复用/释放已构建的对象.在 My.Ioc 中,这个目的是通过 Lifetime/ILifetimeScope 来实现的.其中,Lifeti ...
- List、Set、Map的使用
1.List(接口) List接口的特点: a.List接口可以存放任意数据,且在接口中,数据可以重复. b.List中提供了高效的插入和移除多个元素的方法. List常用的子类 a.ArrayLis ...
- 如何遍历json属性和动态添加属性
var person= { name: 'zhangsan', pass: '123' , 'sni.ni' : 'sss', hello:function (){ for(var i=0;i< ...
- 10分钟 教你学会Linux/Unix下的vi文本编辑器
10分钟 教你学会Linux/Unix下的vi文本编辑器 vi编辑器是Unix/Linux系统管理员必须学会使用的编辑器.看了不少关于vi的资料,终于得到这个总结.不敢独享,和你们共享. 首先,记住v ...
- Java学习----构造方法的重载
一个类中有多个同名的参数不一样(参数的个数,参数的类型,参数的顺序)的构造方法 public class Student { public Student() { System.out.println ...