链接:

https://vjudge.net/problem/POJ-1459

题意:

A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 <= p(u) <= p max(u) of power, may consume an amount 0 <= c(u) <= min(s(u),c max(u)) of power, and may deliver an amount d(u)=s(u)+p(u)-c(u) of power. The following restrictions apply: c(u)=0 for any power station, p(u)=0 for any consumer, and p(u)=c(u)=0 for any dispatcher. There is at most one power transport line (u,v) from a node u to a node v in the net; it transports an amount 0 <= l(u,v) <= l max(u,v) of power delivered by u to v. Let Con=Σ uc(u) be the power consumed in the net. The problem is to compute the maximum value of Con.

An example is in figure 1. The label x/y of power station u shows that p(u)=x and p max(u)=y. The label x/y of consumer u shows that c(u)=x and c max(u)=y. The label x/y of power transport line (u,v) shows that l(u,v)=x and l max(u,v)=y. The power consumed is Con=6. Notice that there are other possible states of the network but the value of Con cannot exceed 6.

思路:

题意很清晰,就是输入很蠢...

建完图直接Dinic.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string> #define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e3+10;
const int INF = 1e9; struct Edge
{
int from, to, flow, cap;
}; vector<int> G[MAXN];
vector<Edge> edges;
int Pow[MAXN], Con[MAXN];
int Vis[MAXN], Dis[MAXN];
int n, np, nc, m;
int s, t; void AddEdge(int from, int to, int cap)
{
edges.push_back(Edge{from, to, 0, cap});
edges.push_back(Edge{to, from, 0, 0});
G[from].push_back(edges.size()-2);
G[to].push_back(edges.size()-1);
} bool Bfs()
{
memset(Dis, -1, sizeof(Dis));
queue<int> que;
que.push(s);
Dis[s] = 0;
while (!que.empty())
{
int u = que.front();
que.pop();
for (int i = 0;i < G[u].size();i++)
{
Edge &e = edges[G[u][i]];
if (e.cap > 0 && Dis[e.to] == -1)
{
que.push(e.to);
Dis[e.to] = Dis[u]+1;
}
}
}
return Dis[t] != -1;
} int Dfs(int u, int flow)
{
if (u == t)
return flow;
int res = 0;
for (int i = 0;i < G[u].size();i++)
{
Edge &e = edges[G[u][i]];
if (e.cap > 0 && Dis[u]+1 == Dis[e.to])
{
int tmp = Dfs(e.to, min(flow, e.cap));
flow -= tmp;
e.cap -= tmp;
res += tmp;
edges[G[u][i]^1].cap += tmp;
if (flow == 0)
break;
}
}
if (res == 0)
Dis[u] = -1;
return res;
} int MaxFlow()
{
int res = 0;
while (Bfs())
{
res += Dfs(s, INF);
}
return res;
} int main()
{
while (~scanf("%d%d%d%d", &n, &np, &nc, &m))
{
int u, v, x;
s = 0, t = n+1;
for (int i = s;i <= t;i++)
G[i].clear();
edges.clear();
// cout << n << ' ' << np << ' ' << nc << ' ' << m << endl;
getchar();
for (int i = 1;i <= m;i++)
{
scanf(" (%d,%d)%d", &u, &v, &x);
// cout << u << ' ' << v << ' ' << x << endl;
u++, v++;
AddEdge(u, v, x);
getchar();
}
for (int i = 1;i <= np;i++)
{
scanf(" (%d)%d", &u, &x);
u++;
AddEdge(0, u, x);
getchar();
}
for (int i = 1;i <= nc;i++)
{
scanf(" (%d)%d", &u, &x);
u++;
AddEdge(u, t, x);
}
int res = MaxFlow();
cout << res << endl;
} return 0;
}

POJ-1459-Pwoer Network(最大流Dinic, 神仙输入)的更多相关文章

  1. POJ 1459 Power Network 最大流(Edmonds_Karp算法)

    题目链接: http://poj.org/problem?id=1459 因为发电站有多个,所以需要一个超级源点,消费者有多个,需要一个超级汇点,这样超级源点到发电站的权值就是发电站的容量,也就是题目 ...

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

  3. poj 1459 Power Network

    题目连接 http://poj.org/problem?id=1459 Power Network Description A power network consists of nodes (pow ...

  4. POJ 1459 Power Network(网络最大流,dinic算法模板题)

    题意:给出n,np,nc,m,n为节点数,np为发电站数,nc为用电厂数,m为边的个数.      接下来给出m个数据(u,v)z,表示w(u,v)允许传输的最大电力为z:np个数据(u)z,表示发电 ...

  5. poj 1459 Power Network : 最大网络流 dinic算法实现

    点击打开链接 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 20903   Accepted:  ...

  6. 2018.07.06 POJ 1459 Power Network(多源多汇最大流)

    Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...

  7. POJ - 1459 Power Network(最大流)(模板)

    1.看了好久,囧. n个节点,np个源点,nc个汇点,m条边(对应代码中即节点u 到节点v 的最大流量为z) 求所有汇点的最大流. 2.多个源点,多个汇点的最大流. 建立一个超级源点.一个超级汇点,然 ...

  8. 网络流--最大流--POJ 1459 Power Network

    #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #incl ...

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

    题目大意:题目说了一大堆,其实都是废话......让人有些不知所云,其实就是给了一些电厂,和一些消费点,然后里面有一些路线什么的,求出消费点可以最多消费的电量是多少. 输入大意: 分析:懂了题意就是一 ...

随机推荐

  1. css让字体细长

    transform: scale(1,3); -ms-transform: scale(1,3); -webkit-transform: scale(1,3); -moz-transform: sca ...

  2. laradock 部署 php 环境 和 laravel/lumen 框架

    环境是windows 10 版本1809,docker 版本18.09.0 首先是下载docker.git, 具体可以参考 http://laradock.io/ 要求 Docker >= 17 ...

  3. c++ 创建 uuid guid

    如果没安装,先安装: [root@localhost]# yum install libuuid-devel #include "uuid/uuid.h" 引用 libuuid.s ...

  4. c++ 事件回调 java

    #pragma once #ifdef __cplusplus extern "C" { #endif typedef void(*sig_t)(int); int FirstEl ...

  5. aiXcoder安装&使用

    1.官网下载 https://www.aixcoder.com/#/setting 1.1介绍 1.2选择对应的下载版本 1.3安装&注册(需关闭IDEA) 安装完进行手机/邮箱注册,下载对应 ...

  6. Vue中使用JSX语法

    一 项目结构 二 App组件 <template> <div id="app"> <fruit/> </div> </temp ...

  7. LSTM用于MNIST手写数字图片分类

    按照惯例,先放代码: import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #载入数据集 ...

  8. vue中的$EventBus.$emit、$on的应用

    今天在项目中遇到的一个需求: 在一个选项卡功能的页面,出现的问题是,当点击选项卡的某个选项时,会同时加载整个选项卡的数据,本身产品就很大,数据很多,所以这个问题无法忽略: 仔细研究下发现,当刚进入页面 ...

  9. 网络编程.TCP分块接收数据(AIO)(IOCP)

    1.前提:每次投递的接收缓冲区 在它返回后 就不再用它进行2次投递了 于是 接收缓冲区 在返回的时候,数据都是 从接收缓冲区的偏移[0]处开始填充的,且 接收缓冲区 可能被填满 也可能未被填满. 1. ...

  10. Java GC日志

    JVM 命令:-Xms5m -Xmx20m -XX:+PrintGCDetails -XX:+PrintCommandLineFlags -XX:+UseSerialGC [GC (Allocatio ...