Cod sursa(job #117635)

Utilizator Pepelea_FlaviuFlaviu Pepelea Pepelea_Flaviu Data 21 decembrie 2007 20:31:54
Problema Reuniune Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.64 kb
var fi,fo:text;
    x11,y11,x12,y12,x21,y21,x22,y22,x31,y31,x32,y32,x5,y5,x6,y6:longint;
    arie,perimetru,arie1,arie2,arie3,arcom1,arcom2,arcom3,ariecomuna:int64;
    per1,per2,per3,pcom1,pcom2,pcom3,percomun:int64;
    ok:byte;
function min(a,b:longint):longint;
begin
  if a<b then min:=a
         else min:=b;
end;
function max(a,b:longint):longint;
begin
  if a>b then max:=a
         else max:=b;
end;
function verif(x1,y1,x2,y2,x3,y3,x4,y4:longint):boolean;
var pct1,pct2:longint;
begin
  verif:=true;
  pct1:=min(y1,y3);
  pct2:=max(y2,y4);
  if abs(pct1-pct2)>(abs(y1-y2)+abs(y3-y4)) then
    begin
      verif:=false; exit; end;
  pct1:=max(x2,x4);
  pct2:=min(x1,x3);
  if (abs(pct1-pct2))>(abs(x2-x1)+abs(x3-x4)) then
    begin
      verif:=false; exit; end;
end;
procedure solv(x1,y1,x2,y2,x3,y3,x4,y4:longint);
begin
  ok:=1;
  y5:=max(y1,y3);
  x5:=max(x1,x3);
  y6:=min(y2,y4);
  x6:=min(x2,x4);
  if verif(x1,y1,x2,y2,x3,y3,x4,y4)=false then ok:=0;
end;
begin
  assign(fi,'reuniune.in'); reset(fi);
  assign(fo,'reuniune.out'); rewrite(fo);
  read(fi,x11,y11,x12,y12);
  read(fi,x21,y21,x22,y22);
  read(fi,x31,y31,x32,y32);
  arie1:=abs(x11-x12)*abs(y11-y12);
  per1:=2*abs(x12-x11)+2*abs(y12-y11);
  arie2:=abs(x21-x22)*abs(y21-y22);
  per2:=2*abs(x21-x22)+2*abs(y21-y22);
  arie3:=abs(x31-x32)*abs(y31-y32);
  per3:=2*abs(x31-x32)+2*abs(y31-y32);
  solv(x11,y11,x12,y12,x21,y21,x22,y22);
  if ok=0 then
     begin
       arcom1:=0; pcom1:=0;
     end
   else
     begin
       arcom1:=abs(x5-x6)*abs(y5-y6);
       pcom1:=2*abs(x5-x6)+2*abs(y5-y6);
     end;
  solv(x11,y11,x12,y12,x31,y31,x32,y32);
  if ok=0 then
     begin
       arcom2:=0; pcom2:=0;
     end
   else
     begin
       arcom2:=abs(x5-x6)*abs(y5-y6);
       pcom2:=2*abs(x5-x6)+2*abs(y5-y6);
     end;
  solv(x21,y21,x22,y22,x31,y31,x32,y32);
  if ok=0 then
     begin
       arcom3:=0; pcom3:=0;
     end
    else
     begin
       arcom3:=abs(x5-x6)*abs(y5-y6);
       pcom3:=2*abs(x5-x6)+2*abs(y5-y6);
     end;
  solv(x11,y11,x12,y12,x21,y21,x22,y22);
  if ok=0 then
     begin
      ariecomuna:=0; percomun:=0;
     end
   else
     begin
       solv(x5,y5,x6,y6,x31,y31,x32,y32);
       if ok=0 then
         begin
           ariecomuna:=0; percomun:=0;
           end
       else
         begin
           ariecomuna:=abs(x5-x6)*abs(y5-y6);
           percomun:=2*abs(x5-x6)*abs(y5-y6);
         end;
     end;
  arie:=arie1-arcom1+arie2-arcom2+arie3-arcom3+ariecomuna;
  perimetru:=per1-pcom1+per2-pcom2+per3-pcom3+percomun;
  write(fo,arie:0:0,' ',perimetru:0:0);
  close(fi);
  close(fo);
end.