BZOJ 3571

Portal

First of all, $ N $ with $ N $ two months also with weights, it is clear that the KM

This question is the product of the minimum spanning tree of ideas and thinking about the same,Unfortunately, the product of a bare minimum spanning tree is on BZOJ the authority ...

Each embodiment consider abstracted as a point $ (sum A, sum B) $, and then thrown into a coordinate system for all points inside, then the answer is that one inverse function $ xcdot y = k $ $ k $ of the smallest point

Take KM points and find the smallest minimum $ sum B $ point $ sum A $ (weighted minimum matching operators put the maximum edge weight negated weighted match), the optimal solution must than two points (or at one of the two points below the line), that is, two points together into a

Optimal solution set $ c $, $ sum A $ minimum points $ a $, $ sum B $ minimum point $ b $

$ C $ easily demonstrated some projections on the lower case

Then it would be subject to solving $ A $ $ b $ lower convex hull. So the question is, too many total points, could not get all the points, how to find the next convex hull?

Clearly there is a conclusion, $ vec {ab} $ distance below $ vec {ab} $ farthest point on the lower convex hull must even have $ SDelta abc $ $ c $ largest convex hulls on certain lower.

$$ tell abc = frac {b} {case timesvec {c}} {2} $$

Expand get together again (Not the same height difference vector arrow Review)

$$ tell abc = frac {b} {case timesvec {C} + {A} Case timesvec {b}} {2} $$

Later known that lump, thrown away, i.e., seeking $ vec {ab} timesvec {c} $ maximum

After finding $ c $, update the answer, $ c $ is not necessarily the optimal solution, we have to traverse the lower convex hull, and therefore continue to go about divide and conquer.

Analysis time complexity, because you want to traverse the whole convex hull, set a number of points on the convex hull of $ S $, each $ {rm KM} $ complexity is $ Theta (N ^ 3) $, overall complexity It is $ Theta (SN ^ 3) $.

In practice, this algorithm is very good, but there is still a very bad situation ...... (not yet run faster violence)

Above a big lump in fact written ZYK


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
program bzoj_3571;
const inf=maxlongint>>1;
type point=record x,y:longint; end;
var lx,ly,slack,pair:array[1..70]of longint;
vx,vy:array[1..70]of boolean;
w,a,b:array[1..70,1..70]of longint;
t,n,i,j:longint;
pa,pb:point;

function (a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;

function find(x:longint):boolean;
var t,y:longint;
begin
vx[x]:=true;
for y:=1 to n do
begin
if vy[y] then continue;
t:=lx[x]+ly[y]-w[x,y];
if t=0 then
begin
vy[y]:=true;
if (pair[y]=0)or(find(pair[y])) then
begin
pair[y]:=x;
exit(true);
end;
end else if t<slack[y] then slack[y]:=t;
end;
exit(false);
end;

function KM:point;
var i,j,d:longint;
begin
fillchar(pair,sizeof(pair),0);
for i:=1 to n do lx[i]:=-inf;
fillchar(ly,sizeof(ly),0);
for i:=1 to n do
for j:=1 to n do if w[i,j]>lx[i] then lx[i]:=w[i,j];
for i:=1 to n do
begin
fillchar(slack,sizeof(slack),$3f);
repeat
fillchar(vx,sizeof(vx),false);
fillchar(vy,sizeof(vy),false);
if find(i) then break;
d:=inf;
for j:=1 to n do if (not vy[j])and(slack[j]<d) then d:=slack[j];
for j:=1 to n do if vx[j] then dec(lx[j],d);
for j:=1 to n do if vy[j] then inc(ly[j],d) else dec(slack[j],d);
until false;
end;
KM.x:=0;
KM.y:=0;
for i:=1 to n do inc(KM.x,a[pair[i],i]);
for i:=1 to n do inc(KM.y,b[pair[i],i]);
end;

function solve(l,r:point):longint;
var t:point;
i,j:longint;
begin
for i:=1 to n do
for j:=1 to n do w[i,j]:=a[i,j]*(r.y-l.y)-b[i,j]*(r.x-l.x);
t:=KM;
if ((t.x=l.x)and(t.y=l.y))or((t.x=r.x)and(t.y=r.y)) then exit(min(l.x*l.y,r.x*r.y));
exit(min(solve(l,t),solve(t,r)));
end;

begin
readln(t);
for t:=1 to t do
begin
readln(n);
for i:=1 to n do
for j:=1 to n do read(a[i,j]);
for i:=1 to n do
for j:=1 to n do read(b[i,j]);
for i:=1 to n do
for j:=1 to n do w[i,j]:=-a[i,j];
pa:=KM;
for i:=1 to n do
for j:=1 to n do w[i,j]:=-b[i,j];
pb:=KM;
writeln(solve(pa,pb));
end;
end.

Original: Big Box  BZOJ 3571


Guess you like

Origin www.cnblogs.com/chinatrump/p/11424159.html