Cod sursa(job #40727)

Utilizator andrewgPestele cel Mare andrewg Data 27 martie 2007 17:58:45
Problema Regiuni Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.56 kb
const maxn = 1001;

type punct = record
        x,y:longint;
     end;
     dreapta = record
        a,b,c:longint;
     end;

var f:text;
    n,m,i,j,k:longint;
    p:array[1..maxn]of punct;
    d:array[1..maxn]of dreapta;
    c:array[1..maxn,1..maxn]of integer;
    fol:array[1..maxn]of boolean;

procedure readdata;
begin
   assign(f,'regiuni.in');
   reset(f);
   readln(f,n,m);
   for i:=1 to n do
   begin
      readln(f,d[i].a,d[i].b,d[i].c);
   end;
   for i:=1 to m do
   begin
      readln(f,p[i].x,p[i].y);
   end;
   close(f);
end;

function semn(j:longint):integer;
begin
   if ((d[i].a*p[j].x)+(d[i].b*p[j].y)+d[i].c<=0) then semn:=0
                                                  else semn:=1;
end;

function ok(x,y:longint):boolean;
var p:longint;
begin
   ok:=true;
   for p:=1 to n do
   begin
      if c[x,p]<>c[y,p] then
      begin
         ok:=false;
         exit;
      end;
   end;
end;

procedure solve;
begin
   for i:=1 to n do
   begin
      for j:=1 to m do
      begin
         k:=semn(j);
         c[j,i]:=k;
      end;
   end;
   k:=0;
   for i:=1 to m do
   begin
      if fol[i]=false then
      begin
         fol[i]:=true;
         for j:=1 to m do
         begin
            if ok(i,j) then
            begin
               fol[j]:=true;
            end;
         end;
         inc(k);
      end;
   end;
end;

procedure writedata;
begin
   assign(f,'regiuni.out');
   rewrite(f);
   writeln(f,k);
   close(f);
end;

begin
   readdata;
   solve;
   writedata;
end.