链接:

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. Jackson 数据类型转换

    转载自:http://www.cnblogs.com/quanyongan/archive/2013/04/16/3024993.html Jackson处理一般的JavaBean和Json之间的转换 ...

  2. Flink数据流图的生成----简单执行计划的生成

    Flink的数据流图的生成主要分为简单执行计划-->StreamGraph的生成-->JobGraph的生成-->ExecutionGraph的生成-->物理执行图.其中前三个 ...

  3. Gradle原理动画讲解(五)

    Gradle原理动画讲解  

  4. ARTS-2

    ARTS的初衷 Algorithm:主要是为了编程训练和学习.每周至少做一个 leetcode 的算法题(先从Easy开始,然后再Medium,最后才Hard).进行编程训练,如果不训练你看再多的算法 ...

  5. STM32 USB开发(三) 基于F105RBT6核心板开发的自定义HID收发(FS)

    硬件设计 该核心板的USB插口有两个,一个是用于USB Slave的,可以用来做HID设备,把模拟STM32模拟为U盘等:另一个是USB Host设备,可以对插上的U盘的数据进行读写. 图中J2是Mi ...

  6. 【Linux开发】CCS远程调试ARM,AM4378

    注意一点:CCS也是安装在Linux主机上的,不是安装在Windows上的,我在Windows上做出了很多尝试,但最终也不没明白究竟要用怎样的格式去执行在ARM-Linux应用程序,out文件ELF可 ...

  7. 【DSP开发】【Linux开发】基于ARM+DSP进行应用开发

    针对当前应用的复杂性,SOC芯片更好能能满足应用和媒体的需求,集成众多接口,用ARM做为应用处理器进行多样化的应用开发和用户界面和接口,利用DSP进行算法加速,特别是媒体的编解码算法加速,既能够保持算 ...

  8. License开源许可证

  9. 第二周总结.Java

    本学期开始学习Java课程了,首先我先说说学习Java的感觉吧,它不像C语言程序设计,但是又有语言开发的共同点.学Java语言重点是面向对象的程序设计,更加的适应生活需要和计算机开发的需要. 总的来讲 ...

  10. [Web 前端] 025 js 的对象、数组和数学对象

    1. Javascript 对象 1.1 创建对象 1.1.1 使用原始的方式创建内置对象 var myObject = new Object(); myObject.name = "lij ...