poj 1459 Power Network

http://poj.org/problem?id=1459

网络流之最大流问题处女作,使用的是Edmonds-Karp算法。此外,这又是一道玩转输入的神题,使用sscanf解析字符串内容。

像本题这种多源多汇的最大流问题,只需建立一个超级源点S和一个超级汇点T即可。S连接所有发电站,T连接所有用户。

AC代码:

#include <queue>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX = 110;
const int INT_MAX = 0x3f3f3f3f;

int map[MAX][MAX],pre[MAX];
int n,np,nc,m;
char ss[30];

queue <int> Q;
bool BFS(int src, int des){///宽搜寻找增广路径
	memset(pre, -1, sizeof(pre));
	while(!Q.empty()) Q.pop();
	pre[src] = 0;
	int index;
	Q.push(src);
	while(!Q.empty()){
		index = Q.front();
		Q.pop();
		for(int i=0; i<=1+n; i++){
			if(pre[i] == -1 && map[index][i] > 0){
				pre[i] = index;
				if(i == des) return true;
				Q.push(i);
			}
		}
	}
	return false;
}

int EK(int src, int des){
	int maxflow = 0;
	while(BFS(src, des)){
		int minflow = INT_MAX;
		for(int i=des; i!=src; i=pre[i])
			minflow = min(minflow, map[pre[i]][i]);
		for(int i=des; i!=src; i=pre[i]){
			map[pre[i]][i] -= minflow;
			map[i][pre[i]] += minflow;
		}
		maxflow += minflow;
	}
	return maxflow;
}

int main(){
	while(scanf("%d%d%d%d",&n,&np,&nc,&m) == 4){
		memset(map, 0, sizeof(map));
		int src = n, des = n + 1;
		int u, v, w;
		for(int i=0; i<m; i++){
			scanf("%s",ss);
			sscanf(ss, "(%d,%d)%d",&u,&v,&w);
			map[u][v] = w;
		}
		for(int i=0; i<np; i++){
			scanf("%s",ss);
			sscanf(ss,"(%d)%d",&v,&w);
			map[src][v] = w;
		}
		for(int i=0; i<nc; i++){
			scanf("%s",ss);
			sscanf(ss,"(%d)%d",&u,&w);
			map[u][des] = w;
		}
		printf("%d\n",EK(src, des));
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现在多张图片下方添加文字的效果,同样可以使用HTML中的`<div>`和CSS中的`position`属性。 首先,将每张图片和对应的文字都放在一个`<div>`标签中,如下所示: ```html <div class="container"> <div class="item"> <img src="your-image-url1.jpg" alt="your-image1"> <p>your text here1</p> </div> <div class="item"> <img src="your-image-url2.jpg" alt="your-image2"> <p>your text here2</p> </div> <div class="item"> <img src="your-image-url3.jpg" alt="your-image3"> <p>your text here3</p> </div> </div> ``` 然后,使用CSS对每个容器设置`position: relative`,并对每个文字设置`position: absolute`,并设置`bottom: 0`,这样就可以将每个文字放在对应的图片下方了。 ```css .container { display: flex; justify-content: space-between; } .item { position: relative; flex-basis: 30%; } .item p { position: absolute; bottom: 0; width: 100%; } ``` 这里使用了`flex`布局来让每个容器之间有间隔,同时使用`flex-basis`来设置每个容器的宽度,可以根据需要进行调整。 完整的代码如下所示: ```html <div class="container"> <div class="item"> <img src="your-image-url1.jpg" alt="your-image1"> <p>your text here1</p> </div> <div class="item"> <img src="your-image-url2.jpg" alt="your-image2"> <p>your text here2</p> </div> <div class="item"> <img src="your-image-url3.jpg" alt="your-image3"> <p>your text here3</p> </div> </div> <style> .container { display: flex; justify-content: space-between; } .item { position: relative; flex-basis: 30%; } .item p { position: absolute; bottom: 0; width: 100%; } </style> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值