POJ Optimal Milking 2012-08-28
2016-03-02 20:55
302 查看
Program poj2112; var n,c,m,mid,s,t:longint; map,a:array[1..300,1..300]of longint; cur,dis:array[1..300]of longint; vh:array[0..300]of longint; Procedure init; var i,j,k:longint; begin readln(n,c,m); for i:=1 to n+c do for j:=1 to n+c do read(map[i,j]); s:=n+c+1;t:=n+c+2; end; Procedure floyed; var i,j,k:longint; begin for k:=1 to n+c do for i:=1 to n+c do for j:=1 to n+c do if (i<>j)and(i<>k)and(j<>k)and(map[i,k]<>0)and(map[k,j]<>0) then begin if (map[i,j]=0)or(map[i,k]+map[k,j]<map[i,j]) then map[i,j]:=map[i,k]+map[k,j]; end; end; Function min(a,b:longint):longint; begin if a<b then min:=a else min:=b; end; Function aug(x,nf:longint):longint; var i,j,d,l,minh,ins:longint; begin if x=t then exit(nf); l:=nf; for i:=cur[x] to t do if (a[x,i]>0)and(dis[x]=dis[i]+1) then begin cur[x]:=i; d:=aug(i,min(l,a[x,i])); dec(a[x,i],d); inc(a[i,x],d); dec(l,d); if (dis[s]=t)or(l=0) then exit(nf-l); end; if nf=l then begin minh:=t; for i:=1 to t do if (a[x,i]>0)and(dis[i]<minh) then begin minh:=dis[i];ins:=i; end; cur[x]:=ins; dec(vh[dis[x]]); if vh[dis[x]]=0 then dis[s]:=t; dis[x]:=minh+1; inc(vh[dis[x]]); end; aug:=nf-l; end; Function flow:longint; var i,j,k:longint; begin flow:=0; fillchar(vh,sizeof(vh),0); vh[0]:=t; fillchar(dis,sizeof(dis),0); for i:=1 to t do cur[i]:=1; fillchar(a,sizeof(a),0); for i:=1 to n do for j:=n+1 to n+c do if (map[i,j]<>0)and(map[i,j]<=mid) then a[i,j]:=1; for i:=1 to n do a[s,i]:=m; for i:=n+1 to n+c do a[i,t]:=1; while dis[s]<t do inc(flow,aug(s,maxlongint)); end; Procedure main; var i,j,k,lc,rc,ans:longint; begin floyed; lc:=0;rc:=200000; ans:=0; while lc<rc-1 do begin mid:=(lc+rc)div 2; if flow=c then begin rc:=mid;ans:=mid;end else lc:=mid; end; writeln(ans); end; Begin assign(input,'input.in');assign(output,'output.out'); reset(input);rewrite(output); init; main; close(input);close(output); end.
相关文章推荐
- Mac下Eclipse内置Tomcat端口被占用问题的解决办法
- linux cmake案例解释
- poj2115 C Looooops 空间 2012-01-14
- Exynos4412 Uboot 编译工具 —— 交叉工具链 arm-linux-gcc 的安装
- linux基础命令
- ios架构
- 网站前端优化
- 将项目部署到Tomcat7时遇到的一点小问题
- 使centos7 支持 exfat2格式分区
- Docker
- Linux搭建
- ubutnu 14.04LTS 安装opencv2.4
- 大神们的网站
- linux 中几个非常有用的指令(1)
- 【shellSort】
- Open Replicator
- linux线程
- 初学Linux
- linux shell for循环解决递归循环目录结构
- linux shell getopt接受脚本参数命令分析