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

可以类似分数规划的做,二分密度,然后转化为最大权闭合子图做,判断是否大于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. Discuz!NT3.6与网站整合(操作用户信息)解决方案

    因为网站要加个论坛,所以就用到了Discuz!NT3.6. 可惜目前官方论坛已经关闭,只有3.6版本的有源码,3.9的没有源码,不好操作,下载地址: http://download.comsenz.c ...

  2. 谈谈Android系统启动时的那点事儿

    Android系统完整的启动过程,从系统层次角度可分为Linux系统层.Android系统服务层.Zygote进程模型三个阶段:从开机到启动Home Launcher完成具体的任务细节可分为七个步骤, ...

  3. 【BZOJ】【2733】【HNOI2012】永无乡

    平衡树+启发式合并+并查集 因为要求一坨数中第k大的……用平衡树会很好维护…… 但又要求连通块?所以用并查集来维护…… 大概就是让并查集的fa和Treap的根是同一个节点吧…… TLE了N多发,可能是 ...

  4. crawler

    # !/usr/bin/env python# encoding:UTF-8from util import request_urlimport reimport osimport sys#from ...

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

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

  6. javascript表格的添加和删除

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  7. lintcode :最大子数组

    题目:  最大子数组 给定一个整数数组,找到一个具有最大和的子数组,返回其最大和. 样例 给出数组[−2,2,−3,4,−1,2,1,−5,3],符合要求的子数组为[4,−1,2,1],其最大和为6 ...

  8. lintcode 中等题:Intersection of Two Linked Lists 两个链表的交叉

    题目 两个链表的交叉 请写一个程序,找到两个单链表最开始的交叉节点. 样例 下列两个链表: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3 在节点 c1 开始交 ...

  9. Filter高级开发

    孤傲苍狼 只为成功找方法,不为失败找借口! javaweb学习总结(四十三)——Filter高级开发 在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以 ...

  10. Spring + JMS + ActiveMQ实现简单的消息队列(监听器异步实现)

    首先声明:以下内容均是在网上找别人的博客综合学习而成的,可能会发现某些代码与其他博主的相同,由于参考的文章比较多,这里对你们表示感谢,就不一一列举,如果有侵权的地方,请通知我,我可以把该文章删除. 1 ...