Cod sursa(job #37274)

Utilizator andrewgPestele cel Mare andrewg Data 24 martie 2007 19:23:36
Problema Pachete Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.11 kb
const maxn = 2000;

type punct = record
        x,y:longint;
     end;
     plan = array[1..maxn]of punct;

var f:text;
    n,i,j,sol:longint;
    p:punct;
    x1,x2,x3,x4:longint;
    a1,a2,a3,a4:plan;

procedure readdata;
var x,y:longint;
begin
   assign(f,'pachete.in');
   reset(f);
   readln(f,n);
   readln(f,p.x,p.y);
   sol:=0;
   x1:=0;
   x2:=0;
   x3:=0;
   x4:=0;
   for i:=1 to n-1 do
   begin
      readln(f,x,y);
      x:=x-p.x;
      y:=y-p.y;
      if (x>=0) and (y>=0) then
      begin
         inc(x1);
         a1[x1].x:=x;
         a1[x1].y:=y;
      end;
      if (x<=0) and (y>=0) then
      begin
         inc(x2);
         a2[x2].x:=-x;
         a2[x2].y:=y;
      end;
      if (x<=0) and (y<=0) then
      begin
         inc(x3);
         a3[x3].x:=-x;
         a3[x3].y:=-y;
      end;
      if (x>=0) and (y<=0) then
      begin
         inc(x4);
         a4[x4].x:=x;
         a4[x4].y:=-y;
      end;
   end;
   p.x:=0;
   p.y:=0;
   close(f);
end;

procedure sort(var a:plan;x:longint);

procedure qsort(l,r:longint);
var i,j:longint;
    x:real;
    y:punct;
begin
   i:=l;
   j:=r;
   x:=a[(l+r) div 2].y;
   repeat
      while a[i].y<x do i:=i+1;
      while x<a[j].y do j:=j-1;
      if i<=j then
      begin
         y:=a[i];
         a[i]:=a[j];
         a[j]:=y;
         i:=i+1;
         j:=j-1;
      end;
   until i>j;
   if l<j then qsort(l,j);
   if i<r then qsort(i,r);
end;

begin
   qsort(1,x);
end;

procedure solve(a:plan;x:longint);
var max:longint;
begin
   if x=0 then exit;
   if x=1 then
   begin
      inc(sol);
      exit;
   end;
   max:=a[x].x;
   sol:=sol+1;
   for i:=x-1 downto 1 do
   begin
      if a[i].x>max then
      begin
         inc(sol);
         max:=a[i].x;
      end;
   end;
end;

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

begin
   readdata;
   sort(a1,x1);
   solve(a1,x1);
   sort(a2,x2);
   solve(a2,x2);
   sort(a3,x3);
   solve(a3,x3);
   sort(a4,x4);
   solve(a4,x4);
   writedata;
end.