Cod sursa(job #37595)

Utilizator andrewgPestele cel Mare andrewg Data 25 martie 2007 11:18:14
Problema Regiuni Scor 10
Compilator fpc Status done
Runda preONI 2007, Runda 4, Clasele 11-12 Marime 1.63 kb
const maxn = 100;

type punct = record
        x,y:longint;
     end;
     dreapta = record
        a,b,c:longint;
     end;
     cuv = array[1..maxn]of boolean;

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]of cuv;
    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);
         if k=0 then c[j,i]:=false
                else c[j,i]:=true;
      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.