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 ...
随机推荐
- C#解leetcode 152. Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Modernizr——为HTML5和CSS3而生!
原文地址:http://www.alistapart.com/articles/taking-advantage-of-html5-and-css3-with-modernizr/ 堂主译文地址:ht ...
- 遍历aspx页面中所有的指定控件
//1.遍历页面中所有的TextBox,并将值设置成String.Empty for (int j = 0; j < this.Controls.Count; j++){ foreac ...
- 关于asp.net中cookie在调试过程中读写正常发布后乱码问题
最近在做的项目发布后出现了乱码的问题,既然出现了乱码很大的可能性是跟编码有关系,所以首先的解决方案就是重新对cookie进行编码, 在写入的cookie的时候编码,在读取的时候解码 在写入cookie ...
- 使用Cxf发布Webservice服务,如果待发布的接口中有重载方法,怎么处理??
使用 @WebMethod(operationName="multiParamByName") 重新指定名字. http://bbs.csdn.net/topics/270059 ...
- Oracle oerr使用
[oracle@cuug ~]$ oerr ora 01555 01555, 00000, "snapshot too old: rollback segment number %s wit ...
- cmakelists 语法学习
1.项目最外层cmake编写:----------用于kdevelop编译器 project(filtering) cmake_minimum_required(VERSION 2.8) ————必须 ...
- (转载)图解Linux系统的系统架构
我以下图为基础,说明Linux的架构(architecture).(该图参考<Advanced Programming in Unix Environment>) 最内层是硬件,最外层是用 ...
- java计算一个月有多少天和多少周
import java.util.Calendar; /** * 功能概述:计算指定年月的天数和周数<br> * 创建时间:2010-5-17 下午05:25:58<br> * ...
- angularJS中XHR与promise
angularJS应用是完全运行在客户端的应用,我们可以通过angularJS构建一个不需依赖于后端,同时能够实现动态内容和响应的web应用,angularJS提供了将应用与远程服务器的信息集成在一起 ...