显然是有源有汇有下界最大流,不刷不知道,一刷吓一跳
发现了我之前求有源有汇有下界最大流的错误,具体见我那篇介绍有下界的网络流的解题报告(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. 使用jQuery调用ASP.NET WebService的简易教程

    鉴于使用Javascript调用Web Service配置略麻烦,所以记录一下. 1. 新建一个Web服务(WebService.asmx) 2. 取消注释// [System.Web.Script. ...

  2. JavaScript基础-面向对象编程<2>

    2.动态添加,修改和删除对象属性和方法 例如:用类Object()创建一个空对象user,然后修改其行为. (1) 添加属性 var user=new Object(); //创建一个没有属性和方法的 ...

  3. Wix: Using Patch Creation Properties - Minor Update

    Based on the project created in Wix: Using Patch Creation Properties - Small Update, Following chang ...

  4. Linux操作系统是如何工作的?破解操作系统的奥秘

    学号:SA12**6112 研究笔记: 1:计算机是怎么样工作的 2:用户态到内核态切换之奥秘解析 3:进程切换之奥秘解析 本博文主要是根据前3篇笔记来总结Linux内核的工作机制. 一:操作系统工作 ...

  5. SSD论文优秀句子

    1. Nonvolatile memory(e.g., Phase Change Memory) blurs the boundary between memory and storage and i ...

  6. 由Double类型数据到数据的格式化包java.text

    需求:Double类型数据截取操作保留两位小数 解决方案: java.text.DecimalFormat df =new java.text.DecimalFormat("#.00&quo ...

  7. jQuery—一些常见方法(2)DOM操作【insertBefore(),insertAfter(),appendTo(),prependTo(),before(),after(),append(),prepend(),remove(),on(),off(),scrollTop()】

    一.insertBefore() 如下代码:找到span标签,将span标签剪切到div的前面 <!DOCTYPE html> <html lang="en"&g ...

  8. 添加数据时候获取自增的ID

    create database dbDemo go use dbDemo go create table tdstudent { id int primary key identity(1,1), n ...

  9. CRUD生成器DBuilder设计与实现

    源码位于github:https://github.com/lvyahui8/dbuilder.git .文中图片如果太小看不清楚,请右键点击“在新标签页中打开”即可看到原图 有兴趣还可以加QQ群交流 ...

  10. 网页制作常见的面试题(怎样兼容IE6/IE7/火狐浏览器)

    1.IE6双边距问题? 在IE6的浏览器中明明设置的是10px的margin却为什么显示的是20px的margin其实这个Ie6的一个双边距BUG例如:<style type="tex ...