显然是有源有汇有下界最大流,不刷不知道,一刷吓一跳
发现了我之前求有源有汇有下界最大流的错误,具体见我那篇介绍有下界的网络流的解题报告(bzoj2502),已经更正

 const inf=;
type node=record
po,next,flow:longint;
end; var e:array[..] of node;
pre,p,numh,h,cur,d:array[..] of longint;
a:array[..,..] of double;
len,tot,i,j,n,s,t,ss,tt:longint; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure add(x,y,f:longint);
begin
inc(len);
e[len].po:=y;
e[len].flow:=f;
e[len].next:=p[x];
p[x]:=len;
end; procedure build(x,y,f:longint);
begin
add(x,y,f);
add(y,x,);
end; function sap(s,t:longint):longint;
var u,neck,tmp,i,j,q:longint;
begin
fillchar(numh,sizeof(numh),);
fillchar(h,sizeof(h),);
for i:= to tt do
cur[i]:=p[i];
u:=s;
sap:=;
numh[]:=tt+;
neck:=inf;
while h[s]<tt+ 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
neck:=min(neck,e[i].flow);
cur[u]:=i;
pre[j]:=u;
u:=j;
if u=t then
begin
sap:=sap+neck;
while u<>s do
begin
u:=pre[u];
j:=cur[u];
dec(e[j].flow,neck);
inc(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;
q:=-;
tmp:=tt;
i:=p[u];
while i<>- do
begin
j:=e[i].po;
if e[i].flow> then
if h[j]<tmp then
begin
q:=i;
tmp:=h[j];
end;
i:=e[i].next;
end;
cur[u]:=q;
h[u]:=tmp+;
inc(numh[h[u]]);
if u<>s then
begin
u:=pre[u];
neck:=d[u];
end;
end;
end;
end; begin
len:=-;
fillchar(p,sizeof(p),);
readln(n);
dec(n);
s:=; t:=*n+; ss:=*n+; tt:=*n+;
for i:= to n+ do
for j:= to n+ do
read(a[i,j]);
for i:= to n do
begin
if a[i,n+]<>trunc(a[i,n+]) then
build(s,i,);
d[i]:=d[i]+trunc(a[i,n+]);
d[s]:=d[s]-trunc(a[i,n+]);
if a[n+,i]<>trunc(a[n+,i]) then
build(i+n,t,);
d[i+n]:=d[i+n]-trunc(a[n+,i]);
d[t]:=d[t]+trunc(a[n+,i]);
end;
for i:= to n do
for j:= to n do
begin
if trunc(a[i,j])<>a[i,j] then build(i,j+n,);
d[i]:=d[i]-trunc(a[i,j]);
d[j+n]:=d[j+n]+trunc(a[i,j]);
end;
for i:=s to t do
if d[i]> then
begin
build(ss,i,d[i]);
tot:=tot+d[i];
end
else if d[i]< then build(i,tt,-d[i]);
build(t,s,inf);
if sap(ss,tt)<>tot then writeln('No')
else writeln(sap(s,t)*);
end.

bzoj3698的更多相关文章

  1. 【BZOJ3698】XWW的难题 有上下界的最大流

    [BZOJ3698]XWW的难题 Description XWW是个影响力很大的人,他有很多的追随者.这些追随者都想要加入XWW教成为XWW的教徒.但是这并不容易,需要通过XWW的考核.XWW给你出了 ...

  2. bzoj3698 XWW的难题

    题意:给你个n * n的实数矩阵,你需要把它中的每个数上/下取整,并满足如下条件: 每行最后一个数等于前面的和. 每列最后一个数等于前面的和. n行n列的那个元素始终为0,不予考虑. 求满足条件下矩阵 ...

  3. [BZOJ3698]XWW的难题解题报告|上下界网络流|有源汇最大流

    XWW是个影响力很大的人,他有很多的追随者.这些追随者都想要加入XWW教成为XWW的教徒.但是这并不容易,需要通过XWW的考核.XWW给你出了这么一个难题:XWW给你一个N*N的正实数矩阵A,满足XW ...

  4. [BZOJ3698] XWW的难题 网络流

    3698: XWW的难题 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 533  Solved: 275[Submit][Status][Discus ...

  5. 【bzoj3698】XWW的难题 有上下界最大流

    题目描述 XWW是个影响力很大的人,他有很多的追随者.这些追随者都想要加入XWW教成为XWW的教徒.但是这并不容易,需要通过XWW的考核.XWW给你出了这么一个难题:XWW给你一个N*N的正实数矩阵A ...

随机推荐

  1. JS原型与原型链终极详解(转)

    JavaScript原型及原型链详解 一. 普通对象与函数对象 JavaScript 中,万物皆对象!但对象也是有区别的.分为普通对象和函数对象,Object,Function 是JS自带的函数对象. ...

  2. PHP学习笔记——上传文件到服务端的文件夹下

    环境 开发包:appserv-win32-2.5.10 服务器:Apache2.2 数据库:phpMyAdmin 语言:php5,java 平台:windows 10 需求 编写一个PHP脚本页面,可 ...

  3. linux 配置Socks51

    VPN大家耳熟能详,但是socks用到的人比较少,那什么是socks呢?请看第二段或者百度百科,socks分别有4和5两个版本,现在5为主流.工作中经常用VPN访问国外,但是同时国内的速度又慢了,让人 ...

  4. c#通过反射获取类上的自定义特性

    c#通过反射获取类上的自定义特性 本文转载:http://www.cnblogs.com/jeffwongishandsome/archive/2009/11/18/1602825.html 下面这个 ...

  5. Ajax请求过程中显示“进度”的简单实现

    Ajax在Web应用中使用得越来越频繁.在进行Ajax调用过程中一般都具有这样的做法:显示一个GIF图片动画表明后台正在工作,同时阻止用户操作本页面(比如Ajax请求通过某个按钮触发,用户不能频繁点击 ...

  6. UNICODE编码表

    UNICODE简介 Unicode(统一码.万国码.单一码)是一种在计算机上使用的字符编码.Unicode 是为了解决传统的字符编码方案的局限而产生的,它为每种语言中的每个字符设定了统一并且唯一的二进 ...

  7. 【Scala 】Akka库

    简介编辑 Akka 是一个用 Scala 编写的库,用于简化编写容错的.高可伸缩性的 Java 和 Scala 的 Actor 模型应用.它已经成功运用在电信行业.系统几乎不会宕机(高可用性 99.9 ...

  8. Spring核心框架 - AOP的原理及源码解析

    一.AOP的体系结构 如下图所示:(引自AOP联盟) 层次3语言和开发环境:基础是指待增加对象或者目标对象:切面通常包括对于基础的增加应用:配置是指AOP体系中提供的配置环境或者编织配置,通过该配置A ...

  9. Python之创建单元素tuple

    tuple和list一样,可以包含 0 个.1个和任意多个元素. 包含多个元素的 tuple,前面我们已经创建过了. 包含 0 个元素的 tuple,也就是空tuple,直接用 ()表示: >& ...

  10. cf Round 601

    A.The Two Routes(BFS) 给出n个城镇,有m条铁路,铁路的补图是公路,汽车和火车同时从1出发,通过每条路的时间为1,不能同时到达除了1和n的其它点,问他们到达n点最少要用多长时间. ...