忘写题解了,经典的最大密度子图

可以类似分数规划的做,二分密度,然后转化为最大权闭合子图做,判断是否大于0

注意方案的输出

 const eps=1e-6;
lim=1e-12;
inf=;
type node=record
po,next:longint;
flow:double;
end; var e:array[..] of node;
numh,h,cur,pre,p,x,y:array[..] of longint;
v:array[..] of boolean;
d:array[..] of double;
len,i,n,m,t,ans:longint;
l,r,mid:double; function min(a,b:double):double;
begin
if a>b then exit(b) else exit(a);
end; procedure add(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; procedure build(x,y:longint;f:double);
begin
add(x,y,f);
add(y,x,);
end; function sap:double;
var u,i,j,tmp,q:longint;
neck:double;
begin
fillchar(numh,sizeof(numh),);
fillchar(h,sizeof(h),);
numh[]:=t+;
u:=;
sap:=;
neck:=inf;
for i:= to t do
cur[i]:=p[i]; while h[]<t+ do
begin
d[u]:=neck;
i:=cur[u];
while i<>- do
begin
j:=e[i].po;
if (e[i].flow>lim) and (h[u]=h[j]+) then
begin
neck:=min(neck,e[i].flow);
pre[j]:=u;
cur[u]:=i;
u:=j;
if u=t then
begin
sap:=sap+neck;
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 break;
q:=-;
tmp:=t;
i:=p[u];
while i<>- do
begin
j:=e[i].po;
if e[i].flow>lim then
if h[j]<tmp then
begin
q:=i;
tmp:=h[j];
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; function dfs(x:longint):boolean;
var i,y:longint;
begin
if x=t then exit(true);
i:=p[x];
v[x]:=true;
while i<>- do
begin
y:=e[i].po;
if (e[i].flow>lim) and not v[y] then
if dfs(y) then exit(true);
i:=e[i].next;
end;
exit(false);
end; function check(w:double):boolean;
var i:longint;
f:double;
begin
len:=-;
fillchar(p,sizeof(p),);
for i:= to m do
begin
build(x[i]+m,i,inf);
build(y[i]+m,i,inf);
build(i,t,);
end;
for i:= to n do
build(,i+m,w);
f:=sap;
if m-f> then
begin
ans:=;
for i:= to n do
begin
fillchar(v,sizeof(v),false);
if dfs(i+m) then inc(ans);
end;
exit(true);
end;
exit(false);
end; begin
readln(n,m);
for i:= to m do
readln(x[i],y[i]);
t:=n+m+;
l:=;
r:=m;
while l+eps<r do
begin
mid:=(l+r)/;
if check(mid) then l:=mid
else r:=mid;
end;
if m= then ans:=; //必须要选
writeln(ans);
end.

bzoj1312的更多相关文章

  1. Bzoj1312 / POJ3155 Neerc2006 Hard Life

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 459  Solved: 114 Description 在一家公司中,人事部经理与业务部经理不和.一次 ...

随机推荐

  1. SVN学习

    一.SVN在线安装(Eclipse) 步骤1: 步骤2 其中http://subclipse.tigris.org/update_1.10.x是最新版本的SVN插件的下载站点[subclipse是Ec ...

  2. linux xampp常见问题

    一.常见问题 1.安装xampp4linux后,只能本机(http://localhost)访问,局域网内其他机器无法访问 解答:在/opt/lampp/etc中修改httpd.conf,将Liste ...

  3. Ruby 语法快速入门

    作用域:指的是类,模块,方法 常量:无需指定类型,全大写 FANS = 100 puts "We have" + FANS.to_s + "fans" 变量 局 ...

  4. Pentaho Data Integration笔记 (一):安装

    介绍 Pentaho Data Integration (PDI) is an extract, transform, and load (ETL) solution that uses an inn ...

  5. MySQL数据库错误server_errno=2013的解决

    MySQL数据库错误server_errno=2013的解决 一组MySQL复制环境中的Master意外掉电,重启后Master运行正常,但该复制环境中的其它slave端,Error Log中却抛出的 ...

  6. c++ 获取本地ip地址

    最终版本:采用指针传参数,不使用别名形式. #include <unistd.h> #include <netdb.h> //gethostbyname #include &l ...

  7. Codeforces Round #343 (Div. 2) E. Famil Door and Roads

    题目链接: http://www.codeforces.com/contest/629/problem/E 题解: 树形dp. siz[x]为x这颗子树的节点个数(包括x自己) dep[x]表示x这个 ...

  8. SQLServer调试

    1.普通调试 直接点击SSMS客户端上的调试按钮即可 2.存储过程调试 2.1 定义存储过程(以Northwind数据库为例) USE [Northwind] GO /****** Object: S ...

  9. 【HDOJ】【4405】Aeroplane chess飞行棋

    概率DP/数学期望 kuangbin总结中的第4题 啊还是求期望嘛……(话说Aeroplane chess这个翻译怎么有种chinglish的赶脚……) 好像有点感觉了…… 首先不考虑直飞的情况: f ...

  10. Unity GameObject.activeSelf, GameObject.activeInHierarchy,GameObject.SetActive和SetActiveRecursively

    activeSelf(read only只读):物体本身的active状态,对应于其在inspector中的checkbox是否被勾选activeInHierarchy(read only只读):物体 ...