Ombrophobic Bovines - POJ 2391
2015-07-23 00:26
405 查看
Description
FJ's cows really hate getting wet so much that the mere thought of getting caught in the rain makes them shake in their hooves. They have decided to put a rain siren on the farm to let them know when rain is approaching. They intend to create a rain evacuation plan so that all the cows can get to shelter before the rain begins. Weather forecasting is not always correct, though. In order to minimize false alarms, they want to sound the siren as late as possible while still giving enough time for all the cows to get to some shelter.
The farm has F (1 <= F <= 200) fields on which the cows graze.
A set of P (1 <= P <= 1500) paths connects them. The paths are
wide, so that any number of cows can traverse a path in either
direction.
Some of the farm's fields have rain shelters under which the cows
can shield themselves. These shelters are of limited size, so a single
shelter might not be able to hold all the cows. Fields are small
compared to the paths and require no time for cows to traverse.
Compute the minimum amount of time before rain starts that the siren must be sounded so that every cow can get to some shelter.
Input
* Line 1: Two space-separated integers: F and P
* Lines 2..F+1: Two space-separated integers that describe a field.
The first integer (range: 0..1000) is the number of cows in that field.
The second integer (range: 0..1000) is the number of cows the shelter
in that field can hold. Line i+1 describes field i.
* Lines F+2..F+P+1: Three space-separated integers that describe a
path. The first and second integers (both range 1..F) tell the fields
connected by the path. The third integer (range: 1..1,000,000,000) is
how long any cow takes to traverse it.
Output
*
Line 1: The minimum amount of time required for all cows to get under a
shelter, presuming they plan their routes optimally. If it not possible
for the all the cows to get under a shelter, output "-1".
Sample Input
Sample Output
Hint
OUTPUT DETAILS:
In 110 time units, two cows from field 1 can get under the shelter
in that field, four cows from field 1 can get under the shelter in field
2, and one cow can get to field 3 and join the cows from that field
under the shelter in field 3. Although there are other plans that will
get all the cows under a shelter, none will do it in fewer than 110 time
units.
题目大意
有F个牛棚,和P条道路
每个牛棚能容纳的牛的数量不同,我们要在最短的时间内移动牛,使得所有的牛都能被容纳
先floyd出最短路
然后二分时间+网络流判定
View Code
FJ's cows really hate getting wet so much that the mere thought of getting caught in the rain makes them shake in their hooves. They have decided to put a rain siren on the farm to let them know when rain is approaching. They intend to create a rain evacuation plan so that all the cows can get to shelter before the rain begins. Weather forecasting is not always correct, though. In order to minimize false alarms, they want to sound the siren as late as possible while still giving enough time for all the cows to get to some shelter.
The farm has F (1 <= F <= 200) fields on which the cows graze.
A set of P (1 <= P <= 1500) paths connects them. The paths are
wide, so that any number of cows can traverse a path in either
direction.
Some of the farm's fields have rain shelters under which the cows
can shield themselves. These shelters are of limited size, so a single
shelter might not be able to hold all the cows. Fields are small
compared to the paths and require no time for cows to traverse.
Compute the minimum amount of time before rain starts that the siren must be sounded so that every cow can get to some shelter.
Input
* Line 1: Two space-separated integers: F and P
* Lines 2..F+1: Two space-separated integers that describe a field.
The first integer (range: 0..1000) is the number of cows in that field.
The second integer (range: 0..1000) is the number of cows the shelter
in that field can hold. Line i+1 describes field i.
* Lines F+2..F+P+1: Three space-separated integers that describe a
path. The first and second integers (both range 1..F) tell the fields
connected by the path. The third integer (range: 1..1,000,000,000) is
how long any cow takes to traverse it.
Output
*
Line 1: The minimum amount of time required for all cows to get under a
shelter, presuming they plan their routes optimally. If it not possible
for the all the cows to get under a shelter, output "-1".
Sample Input
3 4 7 2 0 4 2 6 1 2 40 3 2 70 2 3 90 1 3 120
Sample Output
110
Hint
OUTPUT DETAILS:
In 110 time units, two cows from field 1 can get under the shelter
in that field, four cows from field 1 can get under the shelter in field
2, and one cow can get to field 3 and join the cows from that field
under the shelter in field 3. Although there are other plans that will
get all the cows under a shelter, none will do it in fewer than 110 time
units.
题目大意
有F个牛棚,和P条道路
每个牛棚能容纳的牛的数量不同,我们要在最短的时间内移动牛,使得所有的牛都能被容纳
先floyd出最短路
然后二分时间+网络流判定
const maxn=220; inf=10000000; var first,now,pre,vh,dis,his:array[0..maxn*2]of longint; f:array[0..maxn,0..maxn]of int64; last,next,liu:array[0..maxn*maxn*20]of longint; a,b:array[0..maxn]of longint; n,m,sum,tot:longint; procedure insert(x,y,z:longint); begin inc(tot);last[tot]:=y;next[tot]:=first[x];first[x]:=tot;liu[tot]:=z; inc(tot);last[tot]:=x;next[tot]:=first[y];first[y]:=tot;liu[tot]:=0; end; procedure down(var x:int64;y:int64); begin if x>y then x:=y; end; function flow:longint; var i,j,jl,min,aug:longint; flag:boolean; begin for i:=0 to n<<1+1 do now[i]:=first[i]; for i:=0 to n<<1+1 do vh[i]:=0; for i:=0 to n<<1+1 do dis[i]:=0; vh[0]:=n<<1+2;flow:=0; i:=0;aug:=inf; while dis[i]<n<<1+2 do begin his[i]:=aug; flag:=false; j:=now[i]; while j<>0 do begin if (liu[j]>0) and (dis[i]=dis[last[j]]+1) then begin if aug>liu[j] then aug:=liu[j]; now[i]:=j; pre[last[j]]:=j; i:=last[j]; flag:=true; if i=n<<1+1 then begin inc(flow,aug); while i<>0 do begin dec(liu[pre[i]],aug); inc(liu[pre[i]xor 1],aug); i:=last[pre[i]xor 1]; end; aug:=inf; end; break; end; j:=next[j]; end; if flag then continue; min:=n<<1+1; j:=first[i]; while j<>0 do begin if (liu[j]>0) and (dis[last[j]]<min) then begin min:=dis[last[j]]; jl:=j; end; j:=next[j]; end; dec(vh[dis[i]]); if vh[dis[i]]=0 then break; now[i]:=jl; dis[i]:=min+1; inc(vh[min+1]); if i<>0 then begin i:=last[pre[i]xor 1]; aug:=his[i]; end; end; end; procedure main; var i,j,k,x,y:longint; l,r,z,mid,max:int64; begin fillchar(f,sizeof(f),1); read(n,m); for i:=1 to n do read(a[i],b[i]); for i:=1 to n do inc(sum,a[i]); for i:=1 to n do f[i,i]:=0; for i:=1 to m do begin read(x,y,z); if z<f[x,y] then begin f[x,y]:=z; f[y,x]:=z; end; end; for k:=1 to n do for i:=1 to n do for j:=1 to n do down(f[i,j],f[i,k]+f[k,j]); r:=0; for i:=1 to n do for j:=1 to n do if (r<f[i,j]) and (f[i,j]<f[0,0]) then r:=f[i,j]; l:=0;max:=r;inc(r); while l<>r do begin mid:=(l+r)>>1; tot:=1; for i:=0 to n<<1+1 do first[i]:=0; for i:=1 to n do insert(0,i,a[i]); for i:=1 to n do insert(i+n,n<<1+1,b[i]); for i:=1 to n do for j:=1 to n do if f[i,j]<=mid then insert(i,j+n,inf); if flow>=sum then r:=mid else l:=mid+1; end; if l>max then writeln(-1) else writeln(l); end; begin main; end.
View Code
相关文章推荐
- linux 出行日记(1)
- nginx安装
- tomcat 分别在window 和 Linux上配置SSL-安全问题
- Centos 6.5 final 安装 xtrabackup 2.2.11 小记
- linux内核维护的前期准备工作
- yii nginx 隐藏 index.php
- Strophe + BOSH + Openfire 配置实例
- 结合伙伴系统谈谈linux初始化内存管理区
- PHP 应用 Docker 开发大礼包 – Powered by DaoCloud
- 快速理解Docker - 容器级虚拟化解决方案
- Docker持续部署图文详解
- linux下源码安装python3
- Linux的inode
- Linux Generating SSH keys for GitHub
- JSP页面org.apache.jasper.JasperException异常处理
- 业务层架构模式
- 【Linux】FrameBuffer操作入门
- OpenGL Shader in OpenCASCADE
- Linux下C编程知识整理
- ubuntu14.04 shell脚本用select报错