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分数规划 + 网络流】
题目 现在,保密成为一个很重要也很困难的问题.如果没有做好,后果是严重的.比如,有个人没有自己去修电脑,又没有拆硬盘,后来的事大家都知道了. 当然,对保密最需求的当然是军方,其次才是像那个人.为了应付 ...
随机推荐
- JS实现rgb与16进制颜色相互转换
1.rgb转16进制 function to16 (a) {//RGB(204,204,024) //十六进制颜色值的正则表达式 var reg = /^#([0-9a-fA-f]{3}|[0-9a- ...
- 关于GC进行垃圾回收的时机
前言 今天查看一个同事的代码,发现代码中多处地方使用了GC.Collect()方法,我问他为什么这么做,他说感觉程序中定义了好多变量,怕GC回收不及时,用GC.Collect()可以手动掌控GC进行垃 ...
- iOS 图片按比例压缩,指定大小压缩
使用系统方法UIImageJPEGRepresentation(UIimage *image,CGFloat quality)进行图片质量压缩,暂且叫参数quality为压缩比吧,取值范围为0-1. ...
- OpenJudge 2815 城堡问题 / Poj 1164 The Castle
1.链接地址: http://bailian.openjudge.cn/practice/2815/ http://poj.org/problem?id=1164 2.题目: 总时间限制: 1000m ...
- (转)UIButton用法详解一
(注明 来源网址 http://blog.csdn.net/cheneystudy/article/details/8115092)这段代码动态的创建了一个UIButton,并且把相关常用的属性都列举 ...
- Scala - 处理时间(nscala-time - Joda Time的scala封装)
GITHUB : https://github.com/nscala-time/nscala-time MAVEN : (注意选对scala版本) <dependency> <gro ...
- leetcode problem (2-4)
Problem 2 --- Add Two Numbers 简单的模拟题. Problem 3 --- Longest Substring Without Repeating Characters 题 ...
- 初用jquery
---恢复内容开始--- 这两天在顶顶大人的指导下,利用jquery框架做了一个动态切换的小页面.最终效果图: 这么萌萌哒的图片让我觉得一直在测试也没那么累.实现功能如下: 1.打开页面时,自动切换, ...
- SQL VIEW(视图)
1,视图包含行和列,就像一个真实的表. 2,视图中的字段就是来自一个或多个数据库中的真实的表中的字段. 3,我们可以向视图添加 SQL 函数.WHERE 以及 JOIN 语句,我们也可以提交数据,就像 ...
- MySQL - “Timeout error occurred trying to start MySQL Daemon”解决方法
前几天,网站出现Many connections的问题,进入mysql,show full processlist发现有154个进程,晕....直接service mysqld restart 但是不 ...