显然是有源有汇有下界最大流,不刷不知道,一刷吓一跳
发现了我之前求有源有汇有下界最大流的错误,具体见我那篇介绍有下界的网络流的解题报告(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. php嵌入html的解析过程

    php嵌入html的解析过程 示例: 执行过程:     首先明确:PHP是分段读取一次执行(编译),JS是分段读取分段执行   程序就是对内存的操作     函数可以先调用后定义,原因,程序的执行时 ...

  2. Android SDK下载技巧

    转载说明 本篇文章可能已经更新,最新文章请转:http://www.sollyu.com/android-sdk-download-tips/ 说明 想必在国内的你,是不是经常在下载Android S ...

  3. ubuntu12.04 U盘自动挂载配置

    Ubuntu12.04禁止U盘等设备的自动挂载方法如下: 在图形界面(字符界面无效)内进入系统终端,ctrl+alt+T或者gnome-terminal 禁止自动挂载:$ gsettings seto ...

  4. VS2010类似Eclipse文件查找功能-定位到

    快捷键:Ctrl + , 打开定位到窗口,可以在文件或类文件中查找内容.

  5. Javascript常见全局函数

      ØdecodeURI() 解码某个编码的 URI ØencodeURI() 把字符串编码为 URI ØdecodeURIComponent() 解码一个编码的 URI 组件 ØencodeURIC ...

  6. matlab2014在mac Yosemite下出现java空指针情况

    恢复方法为 使用xcode打开 /System/Library/CoreServices/SystemVersion.plist 将 ProductVersion 下的10.10或10.10.1改为1 ...

  7. 查找计算机IP及占用端口

    1. 在电脑启动搜索框,输入cmd回车打开命令提示符窗口. 输入ipconfig,就可以查看电脑的子网淹没,默认网关,IP等信息. 2. 查看本机开放的端口,即已被占用的端口号. 命令: netsta ...

  8. PHP学习笔记(3) - 奇怪的class与autoload

    PHP的class与其他语言有很多不同点.PHP允许很奇葩的在静态方法中调用实例方法,提供了关键字self和static用于访问类自身的静态成员.self永远是指当前的类,而static则可能会变成指 ...

  9. [数据库连接字符串] Access 连接字符串

    [数据库连接字符串] Access 连接字符串 //ODBC 标准安全策略 Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb ...

  10. 捕获ClientDataSet.ApplyUpdates和SocketConnection异常

    核心提示:如何捕获ClientDataSet.ApplyUpdates的错误,不用ReconcileError... var cdsEmp:TClientDataSet; //保存 procedure ...