POJ 1273 Drainage Ditches
来源:互联网 发布:python数据分析的书 编辑:程序博客网 时间:2024/04/27 08:00
题目链接 : POJ1273
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 46954 Accepted: 17671
Description
Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
Input
The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.
Output
For each case, output a single integer, the maximum rate at which water may emptied from the pond.
Sample Input
5 41 2 401 4 202 4 202 3 303 4 10
Sample Output
50
Source
USACO 93
这个怎么又是最小费用流。。我都不记得题了怎么破wwwww
以后补~
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<string>#include<vector>#include<map>using namespace std;int cap[205][205],fee[205][205];int a[205],p[205],dis[205],que[205];int s,t;int cost_flow(){int ans=0;bool inque[205]={0};while(1){int tail=0,front=1,x;a[s]=0x3fffffff;a[t]=0;for(int i=1;i<=t;i++) dis[i]=0x3fffffff;dis[s]=0;que[0]=s;while(tail<front){x=que[tail++];inque[x]=0;for(int i=1;i<=t;i++)if(fee[x][i]+dis[x]<dis[i] && cap[x][i]>0){dis[i]=dis[x]+fee[x][i];p[i]=x;a[i]=min(a[x],cap[x][i]);if(inque[i]) continue;inque[i]=1;que[front++]=i;}} if(a[t]==0) return ans;x=t;while(x!=s){cap[p[x]][x]-=a[t];cap[x][p[x]]+=a[t];ans+=fee[p[x]][x]*a[t];x=p[x];}}return -1;}int main(){//freopen("1.txt","r",stdin);int n,m;char str[105];int num[2][105];while(scanf("%d%d",&n,&m)){if(n==0 && m==0) break;int k1=0,k2=0;s=0;memset(cap,0,sizeof(cap));memset(fee,0,sizeof(fee));for(int i=0;i<n;i++){scanf("%s",str);for(int j=0;str[j];j++)if(str[j]=='H') num[0][k1++]=i*1000+j;else if(str[j]=='m') num[1][k2++]=i*1000+j;}t=2*k1+1;for(int i=1;i<=k1;i++){cap[0][i]=1;cap[i+k1][t]=1;}for(int i=0;i<k1;i++)for(int j=0;j<k1;j++){cap[i+1][j+k1+1]=0x3fffffff;fee[i+1][j+k1+1]=abs(num[0][i]/1000-num[1][j]/1000)+abs(num[0][i]%1000-num[1][j]%1000);fee[j+k1+1][i+1]=-fee[i+1][j+k1+1];}printf("%d\n",cost_flow());} return 0;}
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ-1273-Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ-1273-Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- 函数指针和函数数组使用
- 求n!,C(n,m)和A(n,m)最后的非零位。
- 有关音频编码的知识与技术参数
- ZOJ 1002 Fire Net (搜索 || 二分图)
- Freebsd ports 安装apache+mod_mono+mono运行.net4.0
- POJ 1273 Drainage Ditches
- 目前为止人生第一次的0分!
- jquery放大镜效果插件
- POJ3619-Speed Reading
- mysql 双机热备份 主主备份 master-master~
- PreparedStatement的用法
- 常用RSS阅读器评测
- pcDuino kernel source code
- CSS学习笔记(十)CSS 字体