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

可以类似分数规划的做,二分密度,然后转化为最大权闭合子图做,判断是否大于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. 团队博客作业Week1 Team Homework #3软件工程在北航

    这次我们采访了一位大四的学姐,让她简单地谈了谈去年学习软件工程的经历和感受. 在完成软件工程大作业的过程中,由于计划安排与实际脱节,导致时间前松后紧,平均每周花在这门课上的时间大约有8个小时. 项目完 ...

  2. 学习KnockOut第三篇之List

    学习KnockOut第三篇之List 欲看此篇---------------------------------------------可先看上篇.          第一步,先搭建一个大概的框架起来 ...

  3. HDU 5486 Difference of Clustering 图论

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5486 题意: 给你每个元素一开始所属的集合和最后所属的集合,问有多少次集合的分离操作,并操作和不变操 ...

  4. javascript小实例,PC网页里的拖拽(转)

    这是现在的效果,可能改了一些,原来的效果是,里面的这张图是可以上下左右拖动的,然后房子上面的显示的楼栋号,也跟着图片一起移动,当时js能力还不行,未能实现项目经理的要求,不过后来项目经理又把这个效果推 ...

  5. 剑指offer--面试题8

    题目:求旋转数组中的最小数字 以下为自己所写代码: #include "stdafx.h" #include <iostream> #include <excep ...

  6. 山寨小小军团开发笔记 之 Arrow Projectile

    好久没怎么更新博客了,今天抽空来一篇,讨论一下弓箭的轨迹生成. 一.原理 弓箭的轨迹本质就是一个数学问题,使用一个 bezier 曲线公式就可以插值生成.得到轨迹后,做一个lookAt就可以了. 二. ...

  7. DevOps 和技术债务偿还自动化

    当企业想要迁移到一个 DevOps 模型时,经常需要偿还高等级的技术债务 说得更明确一点,机构往往陷入「技术债务的恶性循环」中,以至于任何迅速.敏捷的迁移方式都无法使用.这是技术债务中的希腊债务危机水 ...

  8. rabbitMQ安装及部署

    1.安装 rpm -ivh erlang-18.3-1.el6.x86_64.rpm, 下载地址:http://www.rabbitmq.com/releases/erlang/ rpm --impo ...

  9. POJ 1979 Red and Black(水题,递归)

    一开始理解错题意了,以为是走过的砖不能再重复走,最多能走多少个黑砖,结果写的递归陷入死循环...后来才明白原来可以重复走,问可以到达的磁砖数. #include <iostream> #i ...

  10. SDUT图结构练习——最小生成树

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2144&cid=1186 这道题一开始是用prim算法做的,一直错一直错,后来问了帅郭改用 ...