Cod sursa(job #661985)

Utilizator doruletzPetrican Teodor doruletz Data 15 ianuarie 2012 17:37:53
Problema Reuniune Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.49 kb
var x0,x1,y0,y1:array[0..3]of extended;
    aria,perim,aria1,perim1,xfin0,xfin1,yfin0,yfin1:extended;
    i:byte;
    f:text;

function verif(bun,a,b,c,d:extended):boolean;
begin
 if (bun>=a)and(bun<=b)and(bun>=c)and(bun<=d) then verif:=true else verif:=false;
end;

procedure intersect(i,j:byte);
var a0,b0,a1,b1,car,cpr:extended;
begin
 if (x0[i]>=x0[j])and(x0[i]<=x1[j]) then a0:=x0[i]
 else if(x0[j]>=x0[i])and(x0[j]<=x1[i]) then a0:=x0[j]
 else a0:=0;

 if (x1[i]>=x0[j])and(x1[i]<=x1[j]) then a1:=x1[i]
 else if(x1[j]>=x0[i])and(x1[j]<=x1[i]) then a1:=x1[j]
 else a1:=0;

 if (y0[i]>=y0[j])and(y0[i]<=y1[j]) then b0:=y0[i]
 else if (y0[j]>=y0[i])and(y0[j]<=y1[i]) then b0:=y0[j]
 else b0:=0;

 if (y1[i]>=y0[j])and(y1[i]<=y1[j]) then b1:=y1[i]
 else if (y1[j]>=y0[i])and(y1[j]<=y1[i]) then b1:=y1[j]
 else b1:=0;

 if (a0=0)and(a1=0)and(b0=0)and(b1=0) then a0:=0
 else begin
  car:=(b1-b0)*(a1-a0);
  cpr:=2*(b1-b0)+2*(a1-a0);
  if car=0 then cpr:=trunc(cpr/2);
 end;

 //writeln(car,' ',cpr,' pentru coord: ',a0,' ',b0,' si ',a1,' ',b1);
 //readln;
 aria:=aria-car;
 perim:=perim-cpr;
end;

begin
 assign(f,'reuniune.in'); reset(f);
 aria:=0;
 perim:=0;
 for i:=1 to 3 do begin
        readln(f,x0[i],y0[i],x1[i],y1[i]);
        aria:=aria+(x1[i]-x0[i])*(y1[i]-y0[i]);
        perim:=perim+2*(x1[i]-x0[i])+2*(y1[i]-y0[i]);
 end;
 close(f);

 intersect(1,2);
 intersect(1,3);
 intersect(2,3);


 //VERIFIC PUNCT COMUN DE PE Ox LA COLTU STANGA JOS!
 if verif(x0[1],x0[2],x1[2],x0[3],x1[3]) then xfin0:=x0[1]
 else
 if verif(x0[2],x0[1],x1[1],x0[3],x1[3]) then xfin0:=x0[2]
 else xfin0:=x0[3];

 //VERIFIC PUNCT COMPUN DE PE Oy LA COLTU STANGA JOS!
 if verif(y0[1],y0[2],y1[2],y0[3],y1[3]) then yfin0:=y0[1]
 else
 if verif(y0[2],y0[1],y1[1],y0[3],y1[3]) then yfin0:=y0[2]
 else yfin0:=y0[3];

 //VERIFIC PUNCT COMUN DE PE OX LA COLTU DREAPTA SUS!
 if verif(x1[1],x0[2],x1[2],x0[3],x1[3]) then xfin1:=x1[1]
 else
 if verif(x1[2],x0[1],x1[1],x0[3],x1[3]) then xfin1:=x1[2]
 else xfin1:=x1[3];

 //VERIFIC PUNCT COMPUN DE PE Oy LA COLTU DREAPTA SUS!
 if verif(y1[1],y0[2],y1[2],y0[3],y1[3]) then yfin1:=y1[1]
 else
 if verif(y1[2],y0[1],y1[1],y0[3],y1[3]) then yfin1:=y1[2]
 else yfin1:=y1[3];

 aria1:=(yfin1-yfin0)*(xfin1-xfin0);
 perim1:=2*(yfin1-yfin0)+2*(xfin1-xfin0);
 if aria1=0 then perim1:=trunc(perim1/2);

 aria:=aria+aria1;
 perim:=perim+perim1;

 assign(f,'reuniune.out'); rewrite(f);
 writeln(f,trunc(aria),' ',trunc(perim));
 close(f);
end.