POJ1459 Power Network —— 最大流
题目链接:https://vjudge.net/problem/POJ-1459
Time Limit: 2000MS | Memory Limit: 32768K | |
Total Submissions: 29270 | Accepted: 15191 |
Description
An example is in figure 1. The label x/y of power station u shows that p(u)=x and pmax(u)=y. The label x/y of consumer u shows that c(u)=x and cmax(u)=y. The label x/y of power transport line (u,v) shows that l(u,v)=x and lmax(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.
Input
Output
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 (2,4)7(3,5)2 (3,6)5 (4,2)7 (4,3)5 (4,5)1 (6,0)5(0)5 (1)2 (3)2 (4)1 (5)4
Sample Output
15 6
Hint
Source
题意:
有np个供电站(只供电不用电)、nc个用电站(只用电不供电),以及n-np-nc个中转站(既不供电也不用电),且已经知道这些站的连接关系,问单位时间最多能消耗多少的电?
题解:
最大流问题。
1.建立超级源点,超级源点与每个供电站相连,且边的容量为供电站的最大供电量,表明流经此供电站的电量最多只能为自身的供电量。
2.建立超级汇点,每个用电站与超级汇点相连,且边的容量为用电站的最大用电量,表明流经此用电站的电量最多只能为自身的消耗量。
代码如下:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <vector> 6 #include <cmath> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 using namespace std; 13 typedef long long LL; 14 const int INF = 2e9; 15 const LL LNF = 9e18; 16 const int mod = 1e9+7; 17 const int MAXN = 1e2+10; 18 19 int maze[MAXN][MAXN]; 20 int gap[MAXN], dis[MAXN], pre[MAXN], cur[MAXN]; 21 int flow[MAXN][MAXN]; 22 23 int sap(int start, int end, int nodenum) 24 { 25 memset(cur, 0, sizeof(cur)); 26 memset(dis, 0, sizeof(dis)); 27 memset(gap, 0, sizeof(gap)); 28 memset(flow, 0, sizeof(flow)); 29 int u = pre[start] = start, maxflow = 0, aug = INF; 30 gap[0] = nodenum; 31 32 while(dis[start]<nodenum) 33 { 34 loop: 35 for(int v = cur[u]; v<nodenum; v++) 36 if(maze[u][v]-flow[u][v]>0 && dis[u] == dis[v]+1) 37 { 38 aug = min(aug, maze[u][v]-flow[u][v]); 39 pre[v] = u; 40 u = cur[u] = v; 41 if(v==end) 42 { 43 maxflow += aug; 44 for(u = pre[u]; v!=start; v = u, u = pre[u]) 45 { 46 flow[u][v] += aug; 47 flow[v][u] -= aug; 48 } 49 aug = INF; 50 } 51 goto loop; 52 } 53 54 int mindis = nodenum-1; 55 for(int v = 0; v<nodenum; v++) 56 if(maze[u][v]-flow[u][v]>0 && mindis>dis[v]) 57 { 58 cur[u] = v; 59 mindis = dis[v]; 60 } 61 if((--gap[dis[u]])==0) break; 62 gap[dis[u]=mindis+1]++; 63 u = pre[u]; 64 } 65 return maxflow; 66 } 67 68 int main() 69 { 70 int n, np, nc, m; 71 while(scanf("%d%d%d%d", &n,&np,&nc,&m)!=EOF) 72 { 73 int start = n, end = n+1; 74 memset(maze, 0, sizeof(maze)); 75 for(int i = 1; i<=m; i++) 76 { 77 int u, v, w; 78 while(getchar()!='('); 79 scanf("%d,%d)%d",&u,&v,&w); 80 maze[u][v] = w; 81 } 82 83 for(int i = 1; i<=np; i++) 84 { 85 int id, p; 86 while(getchar()!='('); 87 scanf("%d)%d", &id,&p); 88 maze[start][id] = p; 89 } 90 91 for(int i = 1; i<=nc; i++) 92 { 93 int id, p; 94 while(getchar()!='('); 95 scanf("%d)%d", &id,&p); 96 maze[id][end] = p; 97 } 98 99 cout<< sap(start, end, n+2) <<endl; 100 } 101 }
View Code
转载于:https://www.cnblogs.com/DOLFAMINGO/p/8081368.html
POJ1459 Power Network —— 最大流相关推荐
- POJ-1459 Power Network 网络流
题意:给定一些散列的源点会汇点,求解网络流. 代码如下: #include <cstdlib> #include <cstring> #include <cstdio&g ...
- 【POJ - 1459】Power Network(网络流最大流,建图)
题干: A power network consists of nodes (power stations, consumers and dispatchers) connected by power ...
- POJ 1459 -- Power Network(最大流, 建图)
题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...
- Power Network POJ - 1459(EK算法模板+详解)
题意: 总共有a个节点,其中有发电站b个.用户c个和调度器a-b-c个三种节点,每个发电站有一个最大发电量,每个用户有个最大接受电量,现在有d条有向边,边有一个最大的流量代表,最多可以流出这么多电,现 ...
- 第二十七课:Power Network Synthesis(PNS)
总览 前面完成了IO pad 及macro cell的placement及congestion的消除,本节课开始说明PG network的放置并满足congestion与timing delay: 整 ...
- POJ - 1459 Power Network(网络流-最大流)
题目链接:点击查看 题目大意:题意属实恶心,借用别的大佬的题意: 题目描述 一个电网包含一些结点(电站.消费者.调度站),这些结点通过电线连接.每个结点 uu 可能被供给 s(u) 的电能, s(u) ...
- Power Network [POJ - 1459]
题解: 最大流模板题 dinic算法 建立一个超级源点跟超级汇点,把超级源点连接到发电厂,流量设为发电厂发电量 超级汇点跟耗电的用户连接,流量为消耗的电能 发电场和消耗电能的工厂用题目所给数据连接即可 ...
- 初涉网络流 POJ 1459 Power Network
怒搞一下午网络流,又去我一块心病. 从2F到SAP再到Dinic最终过掉了. 但是书上说Dinic的时间复杂度为v*v*e.感觉也应该超时的啊,但是过掉了,好诡异. 后两种算法都是在第一种的基础上进行 ...
- POJ 1459 Power Network
题意:有n个据点,np个发电机.nc个用户,m条电线.给出发电机.用户.电线的电流限制,求最大网络电流. 这是带节点的网络流.事实上和原来没什么差别,仅仅要在前后都添加一个据点,在这里我加了0和n+1 ...
最新文章
- 写聊天室之前 了解聊天室拓展出来的各种知识点
- 直观判断图像是否可以被实时处理
- aPaaS将如何改变软件行业?
- [导入]存储过程-分隔符号-多条件查询
- mysql5.7安装教程绿色_mysql 5.7.17 安装配置方法图文教程(windows)
- IDEA的postfix自定义,自定义postfix
- 贴一个数据结构老师布置的作业(各种排序) c 语言实现
- IT兄弟连 JavaWeb教程 文件下载技术
- MacBook常用快捷键有哪些?
- android 屏幕共享 chrome,Chrome屏幕共享功能接入指南
- 流程图常用符号及其代表含义
- 华硕主板如何设置开机自启_华硕主板怎么设置自动开机,华硕主板设置通电开机-...
- 电压源和电流的关联参考方向_电压电流为关联参考方向.PPT
- 黑白双煞拆装箱 -- 八大基本类型及其封装类
- NEFU OJ 574 丑数
- 谷歌浏览器崩溃,打不开网页,也打不开设置
- Qt 信号槽的应用(三)
- Linux红帽认证工程师(RHCE)考试笔记(Ansible学习笔记)
- scale-free
- 蓝牙BQB认证 Profile测试
热门文章
- 国内高速前端 Unpkg CDN 替代方案
- Hi3520d uboot uImage rootfs 移植与升级
- c++服务器websocket支持
- Linux互斥锁的使用代码实现
- c#按ESC退出 或者接受其他键盘消息
- dos下登录fedora下的vsftp失败
- [react-router] 在history模式中push和replace有什么区别?
- Taro+react开发(86):资源文件处理
- Taro+react开发(45)taro中组件生命周期
- React开发(139):ant design学习指南之下载文件