bzoj2285
完全是为了拼凑才出出来的吧
先分数规划求出到基地入口的最小安全系数
然后再最小点权覆盖集,只不过这里是带一定精度实数的流,其实是一样的
const inf=;
eps=0.001;
type way=record
po,next,ti,sa:longint;
end;
node=record
po,next:longint;
flow:double;
end; var w:array[..] of way;
e:array[..] of node;
d:array[..] of double;
numh,h,pp,p,cur,pre:array[..] of longint;
q:array[..] of longint;
v:array[..] of boolean;
i,t,n,m,m1,len,x,y,z,b:longint;
ans:double; function min(a,b:double):double;
begin
if a>b then exit(b) else exit(a);
end; procedure add(x,y,a,b:longint);
begin
inc(len);
w[len].po:=y;
w[len].ti:=a;
w[len].sa:=b;
w[len].next:=pp[x];
pp[x]:=len;
end; procedure ins(x,y:longint;f:double);
begin
inc(len);
e[len].po:=y;
e[len].flow:=f;
e[len].next:=p[x];
p[x]:=len;
end; function check(t:longint;m:double):boolean;
var x,y,f,r,i:longint;
begin
for i:= to n do
d[i]:=inf;
d[n]:=;
fillchar(v,sizeof(v),false);
f:=;
r:=;
q[]:=n;
while f<=r do
begin
x:=q[f];
v[x]:=false;
i:=pp[x];
while i<> do
begin
y:=w[i].po;
if d[y]>d[x]+w[i].ti-m*w[i].sa then
begin
d[y]:=d[x]+w[i].ti-m*w[i].sa;
if (y=t) and (d[y]<=) then exit(true);
if not v[y] then
begin
v[y]:=true;
inc(r);
q[r]:=y;
end;
end;
i:=w[i].next;
end;
inc(f);
end;
if d[t]<= then exit(true) else exit(false);
end; function calc(x:longint):double;
var l,r,m:double;
begin
l:=;
r:=;
if not check(x,) then exit(inf);
while r-l>eps do
begin
m:=(l+r)/;
if check(x,m) then r:=m else l:=m;
end;
exit(r);
end; procedure sap;
var u,i,j,tmp,q:longint;
neck:double;
begin
u:=;
for i:= to t do
cur[i]:=p[i];
numh[]:=t+;
neck:=inf;
while h[]<t+ do
begin
d[u]:=neck;
i:=cur[u];
while i<>- do
begin
j:=e[i].po;
if (e[i].flow>) and (h[u]=h[j]+) then
begin
pre[j]:=u;
cur[u]:=i;
neck:=min(neck,e[i].flow);
u:=j;
if u=t then
begin
ans:=ans+neck;
if ans>inf then exit;
while u<> do
begin
u:=pre[u];
j:=cur[u];
e[j].flow:=e[j].flow-neck;
e[j xor ].flow:=e[j xor ].flow+neck;
end;
neck:=inf;
end;
break;
end;
i:=e[i].next;
end;
if i=- then
begin
dec(numh[h[u]]);
if numh[h[u]]= then exit;
tmp:=t;
q:=-;
i:=p[u];
while i<>- do
begin
j:=e[i].po;
if e[i].flow> then
if tmp>h[j] then
begin
tmp:=h[j];
q:=i;
end;
i:=e[i].next;
end;
h[u]:=tmp+;
inc(numh[h[u]]);
cur[u]:=q;
if u<> then
begin
u:=pre[u];
neck:=d[u];
end;
end;
end;
end; begin
readln(n,m);
for i:= to m do
begin
readln(x,y,z,b);
add(x,y,z,b);
end;
len:=-;
fillchar(p,sizeof(p),);
readln(m1,t);
inc(t);
for i:= to t- do
if i mod = then
begin
ins(i,t,calc(i));
ins(t,i,);
end
else begin
ins(,i,calc(i));
ins(i,,);
end; for i:= to m1 do
begin
readln(x,y);
ins(x,y,inf);
ins(y,x,);
end;
sap;
if ans>inf then writeln(-)
else writeln(ans::);
end.
bzoj2285的更多相关文章
- 【BZOJ2285】[SDOI2011]保密(分数规划,网络流)
[BZOJ2285][SDOI2011]保密(分数规划,网络流) 题面 BZOJ 洛谷 题解 首先先读懂题目到底在干什么. 发现要求的是一个比值的最小值,二分这个最小值\(k\),把边权转换成\(t- ...
- BZOJ2285 : [Sdoi2011]保密
首先通过分数规划,二分答案$mid$,将每条边边权重置为$t-mid\times s$,用DP求出终点到该点的最短路,若非正则可以更小. 如此可以计算出每个出入口的最小危险值,然后把奇点放在$S$,偶 ...
- BZOJ2285 [SDOI2011]保密 【01分数规划 + 网络流】
题目 现在,保密成为一个很重要也很困难的问题.如果没有做好,后果是严重的.比如,有个人没有自己去修电脑,又没有拆硬盘,后来的事大家都知道了. 当然,对保密最需求的当然是军方,其次才是像那个人.为了应付 ...
随机推荐
- 计算Android屏幕解锁组合数
晚饭时和同事聊到安卓屏幕解锁时会有多少种解锁方案,觉得很有趣,吃完饭开始想办法解题,花了大概2个小时解决.思路如下: 使用索引值0-9表示从左到右.从上到下的9个点,行.列号很容易从索引值得到: 使用 ...
- UIView转场动画属性设置
常规动画属性设置(可以同时选择多个进行设置) UIViewAnimationOptionLayoutSubviews:动画过程中保证子视图跟随运动. UIViewAnimationOptionAllo ...
- HDU 4294 A Famous Equation(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4249 题目大意:给一个a+b=c的表达式,但是a.b.c中部分位的数字丢失,并用?代替,问有多少种方案 ...
- 解决读写properties属性文件
package com.kzkj.wx.utils; import java.io.BufferedReader; import java.io.File; import java.io.FileIn ...
- 浅析JAVA设计模式(三)
4.接口隔离原则: ISP(Interface Segregation Principle) 客户端不应该依赖它不需要的接口,或者说类的依赖的关系应该建立在最小的接口上.举个例子,直接上代码: 1 ...
- windows phone 8 设置锁屏背景
本来想研究一下 利用闪光灯实现手电筒的代码,发现不是简答设置FlashMode属性可以解决问题的,ms也没有提供api,无意瞄了一眼侧边栏的文章列表,发现了设置屏幕锁屏背景的实现,手一抖点进去了.还算 ...
- 利用OllyDebug查看程序调用的dll模块
最近在做一个Qt项目,在产品发布的时候一直为找不到程序到底缺少了哪些dll组件而困扰.具体问题是,在我的项目中使用到了QMediaPlayer播放一段音频文件,我使用的开发环境的Win7 32位,而在 ...
- easy ui tree 取复选框打勾的值
var nodes = $('#basetree').tree('getChecked'); var cnode = ''; for ( var i = 0; i < nodes.length; ...
- 修改win8系统中启动管理器的系统引导信息
最近用某软件做了个启动U盘,软件安装在电脑上,启动盘很快做完了,结果重启电脑的时候发现悲剧,windows启动后会显示出一个系统引导菜单,显示有3秒倒计时但是倒计时结束依然不能自动进入系统.. 然后. ...
- 10分钟进阶Nuget
nuget是什么 .net版的maven(java)? 如果你用过windows的chocolatey,mac的homebrew或许更容易理解他,先来回顾下以前我们是如何处理或者碰到过的问题. 1.假 ...