Cod sursa(job #37618)

Utilizator andradaqAndrada Georgescu andradaq Data 25 martie 2007 11:27:43
Problema Regiuni Scor 100
Compilator fpc Status done
Runda preONI 2007, Runda 4, Clasa a 10-a Marime 1.13 kb
var f:text;
    x,y,a,b,c:array[1..1000] of integer;
    l:array[1..1000,1..34] of longint;
    ex:array[1..1000] of boolean;
    n,m,i,j,zn:integer;
    t,o:longint;


function semn(x,y,a,b,c:integer):byte;
begin
if longint(x)*longint(a)+longint(y)*longint(b)+longint(c)
<0 then semn:=0 else semn:=1;
end;

function egal(i,j:integer):boolean;
var k:integer;
begin
egal:=false;
for k:=1 to n div 30 +1 do if l[i,k]<>l[j,k] then exit;
egal:=true;
end;

begin
assign(f,'regiuni.in'); reset(f);
readln(f,n,m);
for i:=1 to n do readln(f,a[i],b[i],c[i]);
for i:=1 to m do readln(f,x[i],y[i]);
close(f);
for i:=1 to m do
 begin
 t:=0;
 for j:=1 to n do
  begin
  o:=semn(x[i],y[i],a[j],b[j],c[j]);
  t:=(t shl 1)+o;
  if (j mod 30=0) or (j=n) then
   begin
   if j mod 30=0 then l[i,j div 30]:=t
                 else l[i,j div 30+1]:=t;
   t:=0;
   end;
  end;
 end;

assign(f,'regiuni.out'); rewrite(f);
zn:=0;
fillchar(ex,sizeof(ex),0);
for i:=1 to m do
 if not ex[i] then
  begin
  inc(zn);
  ex[i]:=true;
  for j:=i+1 to m do
   if egal(i,j) then ex[j]:=true;
  end;
writeln(f,zn);
close(f);
end.