poj 2536 Gopher II 最大匹配

题目大意:有n只地鼠和m个地洞,每只地鼠的速度相同。求在s秒内有多少只地鼠不能进入地洞。

方法:先根据地鼠和地洞建一个二分图,然后进行最大匹配就好了。

下面附程序:

var
  t,l,n,m,s,v1,i,j,ans:longint;
  p,q:real;
  x,y:array[1..100] of real;
  v:array[1..100] of boolean;
  a:array[1..100,1..100] of boolean;
  link:array[1..100] of longint;

function find(x:longint):boolean;
var
  i,p:longint;
begin
  find:=false;
  for i:=1 to m do
    if (v[i])and(a[x,i]) then
    begin
      p:=link[i]; link[i]:=x; v[i]:=false;
      if (p=0)or(find(p)) then exit(true);
      link[i]:=p;
    end;
end;

begin
  while not eof do
  begin
    readln(n,m,s,v1);
    for i:=1 to n do
      readln(x[i],y[i]);
    fillchar(a,sizeof(a),false);
    for i:=1 to m do
    begin
      readln(p,q);
      for j:=1 to n do
        if sqr(x[j]-p)+sqr(y[j]-q)<=sqr(s*v1) then a[j,i]:=true;
    end;
    fillchar(link,sizeof(link),0);
    for i:=1 to n do
    begin
      fillchar(v,sizeof(v),true);
      find(i);
    end;
    ans:=0;
    for i:=1 to m do
      if link[i]>0 then inc(ans);
    writeln(n-ans);
  end;
end.


你可能感兴趣的:(poj 2536 Gopher II 最大匹配)