ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1245. Pictures

why my codes got WA, who can give me some testdata please?
Posted by BShell 16 May 2003 15:58
type point=record
             x,y,r:longint;
           end;

var a:array[1..1000] of point;
    l,r:array[1..1000] of longint;
    lx,rx:array[1..1000] of record
                              up,low:longint;
                            end;
    x1,x2,y1,y2,n,i:longint;
    ans,s:extended;

function min(a,b:longint):longint;
begin
  if a>b then min:=b
  else min:=a;
end;

function max(a,b:longint):longint;
begin
  if a>b then max:=a
  else max:=b;
end;

procedure qsort(r,p,flag:longint);
var i,j:longint;
    k,t:point;

  function bigger(a,b:point;flag:longint):boolean;
  begin
    bigger:=(flag=1) and (a.x>=b.x) or (flag=2) and (a.y>=b.y);
  end;

begin
  k:=a[random(p-r+1)+r];
  i:=r-1;
  j:=p+1;
  repeat
    repeat inc(i); until bigger(a[i],k,flag);
    repeat dec(j); until bigger(k,a[j],flag);
    if i<j then
    begin
      t:=a[i];
      a[i]:=a[j];
      a[j]:=t;
    end;
  until i>=j;
  if r<j then qsort(r,j,flag);
  if j+1<p then qsort(j+1,p,flag);
end;

begin
  readln(n);
  for i:=1 to n do
    readln(a[i].r,a[i].x,a[i].y);
  randomize;
  qsort(1,n,1);
  fillchar(l,sizeof(l),0);
  fillchar(r,sizeof(r),0);
  fillchar(lx,sizeof(lx),0);
  fillchar(rx,sizeof(rx),0);
  r[1]:=a[1].x+a[1].r;
  for i:=2 to n do
    r[i]:=max(a[i].x+a[i].r,r[i-1]);
  l[n]:=a[n].x-a[n].r;
  for i:=n-1 downto 1 do
    l[i]:=min(a[i].x-a[i].r,l[i+1]);
  lx[1].up:=a[1].y+a[1].r;
  lx[1].low:=a[1].y-a[1].r;
  for i:=2 to n do
  begin
    lx[i].up:=max(a[i].y+a[i].r,lx[i-1].up);
    lx[i].low:=min(a[i].y-a[i].r,lx[i-1].low);
  end;
  rx[n].up:=a[n].y+a[n].r;
  rx[n].low:=a[n].y-a[n].r;
  for i:=n-1 downto 1 do
  begin
    rx[i].up:=max(a[i].y+a[i].r,rx[i+1].up);
    rx[i].low:=min(a[i].y-a[i].r,rx[i+1].low);
  end;
  ans:=(r[n]-l[1])*(lx[n].up-lx[n].low);
  for i:=1 to n-1 do
  if r[i]<l[i+1] then
  begin
    x1:=max(r[i]-l[1],100);
    y1:=max(lx[i].up-lx[i].low,100);
    x2:=max(r[n]-l[i+1],100);
    y2:=max(rx[i+1].up-rx[i+1].low,100);
    s:=x1*y1+x2*y2;
    if s<ans then ans:=s;
  end;
  qsort(1,n,2);
  fillchar(l,sizeof(l),0);
  fillchar(r,sizeof(r),0);
  fillchar(lx,sizeof(lx),0);
  fillchar(rx,sizeof(rx),0);
  r[1]:=a[1].y+a[1].r;
  for i:=2 to n do
    r[i]:=max(a[i].y+a[i].r,r[i-1]);
  l[n]:=a[n].y-a[n].r;
  for i:=n-1 downto 1 do
    l[i]:=min(a[i].y-a[i].r,l[i+1]);
  lx[1].up:=a[1].x+a[1].r;
  lx[1].low:=a[1].x-a[1].r;
  for i:=2 to n do
  begin
    lx[i].up:=max(a[i].x+a[i].r,lx[i-1].up);
    lx[i].low:=min(a[i].x-a[i].r,lx[i-1].low);
  end;
  rx[n].up:=a[n].x+a[n].r;
  rx[n].low:=a[n].x-a[n].r;
  for i:=n-1 downto 1 do
  begin
    rx[i].up:=max(a[i].x+a[i].r,rx[i+1].up);
    rx[i].low:=min(a[i].x-a[i].r,rx[i+1].low);
  end;
  for i:=1 to n-1 do
  if r[i]<l[i+1] then
  begin
    x1:=max(r[i]-l[1],100);
    y1:=max(lx[i].up-lx[i].low,100);
    x2:=max(r[n]-l[i+1],100);
    y2:=max(rx[i+1].up-rx[i+1].low,100);
    s:=x1*y1+x2*y2;
    if s<ans then ans:=s;
  end;
  writeln(ans:0:0);
end.