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分数规划 + 网络流】
题目 现在,保密成为一个很重要也很困难的问题.如果没有做好,后果是严重的.比如,有个人没有自己去修电脑,又没有拆硬盘,后来的事大家都知道了. 当然,对保密最需求的当然是军方,其次才是像那个人.为了应付 ...
随机推荐
- Linux的各种命令(android adb shell)
win+r 调出运行,输入CMD adb shell 进入手机的控制终端,相当于原生的Linux系统的各种操作. 当提示符为$符号,说明未获得超级管理员权限,输入su,可编程# adb kill-se ...
- 使用反射让Spinner选择同一选项时触发onItemSelected事件
翻看源码,Spinner判断是否触发onItemSelected,是在它的基类AdapterView里面做的: void checkSelectionChanged() { if ((mSelecte ...
- 周末充电之WPF(三 ) .后台动态生成控件
布局 -连连看: 代码: private void Window_Loaded_1(object sender, RoutedEventArgs e) { //动态创建行 ; i < ; i++ ...
- react native ios 开发,基础配置笔记。
一.获取硬件信息,使用react-native-device-info插件,配置说明: 1.首先需要安装组件:npm install react-native-device-info --save 2 ...
- OpenCV(5)-图像掩码操作(卷积)-锐化
锐化概念 图像平滑过程是去除噪声的过程.图像的主要能量在低频部分,而噪声主要集中在高频部分.图像的边缘信息主要也在高频部分,在平滑处理后,将会丢不部分边缘信息.因此需要使用锐化技术来增强边缘. 平滑处 ...
- Oracle 10g 下载地址
Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit ...
- ubuntu logout 命令
gnome-session-quit 点击打开链接http://askubuntu.com/questions/15795/how-can-you-log-out-via-the-terminal
- PHP分页初探 一个最简单的PHP分页代码实现
PHP分页代码在各种程序开发中都是必须要用到的,在网站开发中更是必选的一项. 要想写出分页代码,首先你要理解SQL查询语句:select * from goods limit 2,7.PHP分页代码核 ...
- shell中case的用法学习笔记
这篇文章主要为大家介绍shell中的case语句:可以把变量的内容与多个模板进行匹配,再根据成功匹配的模板去决定应该执行哪部分代码. 本文转自:http://www.jbxue.com/article ...
- php最短的HTTP响应代码
刚刚发现在CodeProject给我推送了一篇文章叫:the Shortest PHP code for Returning HTTP Response Code 翻译过来就是(PHP最短的HTTP ...