bzoj1312
忘写题解了,经典的最大密度子图
可以类似分数规划的做,二分密度,然后转化为最大权闭合子图做,判断是否大于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的更多相关文章
- Bzoj1312 / POJ3155 Neerc2006 Hard Life
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 459 Solved: 114 Description 在一家公司中,人事部经理与业务部经理不和.一次 ...
随机推荐
- SpringMVC+redis整合
在网络上有一个很多人转载的springmvc+redis整合的案例,不过一直不完整,也是被各种人装来转去,现在基本将该框架搭建起来. package com.pudp.bae.base; import ...
- [转载+原创]Emgu CV on C# (七) —— Emgu CV on 轮廓检测
轮廓检测 对于查找轮廓我们一般要对图像Canny检测.但是对于很特殊的场合其实我们还可以直接对二值化的图像进行轮廓的提取. 关键函数 1. cvFindContours Retrieves conto ...
- (C#)的命名规范
http://gray.iteye.com/blog/644626 http://developer.51cto.com/art/200908/143787.htm http://blog.csdn. ...
- 【转载】Hadoop历史服务器详解
免责声明: 本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除. 原文作者:过往记忆(http://www.iteblog.com/) 原文地址: ...
- 【转载】CCombobox使用大全
一.如何添加/删除Combo Box内容 1. 在Combo Box控件属性的Data标签里面添加,一行表示Combo Box下拉列表中的一行.换行用ctrl+回车. 2. 在程序初始化时动态添加 如 ...
- shallow copy & deep copy
1.深复制与浅复制的概念 ->浅复制(shallow copy)概念 在SDK Guides中(搜索copy),官方给出的浅复制概念为: Copying compound objects, ...
- sql over()---转载
1.使用over子句与rows_number()以及聚合函数进行使用,可以进行编号以及各种操作.而且利用over子句的分组效率比group by子句的效率更高. 2.在订单表(order)中统计中,生 ...
- poj 1562 Oil Deposits (广搜,简单)
题目 简单的题目,只是测试案例的输入后面可能有空格,所以要注意一下输入方式. #define _CRT_SECURE_NO_WARNINGS //题目的案例输入n,m后面有些貌似有空格... #inc ...
- POJ 3111
K Best Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 5177 Accepted: 1411 Case Time ...
- HttpWebRequest和HttpWebResponse
原文:http://blog.csdn.net/haitaofeiyang/article/details/18362225 申公前几日和一个客户做系统对接,以前和客户对接一般采用webservice ...