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 1207. Median on the Plane

who can help me with 7-th test.? thanks
Posted by VALERO 11 Aug 2006 14:51
maybe, you can give any tests where my program doesnt work?
my algo is :

var a : array[0..100001,1..3] of int64;
    n,i,o,k,l : longint;
    q,w,e,k1,k2,k3,k4 : int64;
    s,d : real;

procedure sort(l,r: longint);
     var i,j :longint;
         x,y,z,w: int64;
   begin
     i := l;
     j := r;
     x := A[ (l + r) div 2,1 ];
     repeat
       while A[i,1] < x do inc(i);
       while x < A[j,1] do dec(j);
       if not (i>j) then
         begin
           y    := A[i,1];
           A[i,1] := A[j,1];
           A[j,1] := y;
           z    := A[i,2];
           A[i,2] := A[j,2];
           A[j,2] := z;
           w    := A[i,3];
           A[i,3] := A[j,3];
           A[j,3] := w;

           inc(i);
           dec(j);
         end;
     until i>j;
     if l < j then sort(l,j);
     if i < r then sort(i,r);
   end;


procedure vuv;
begin
if a[k1,3]<a[k2,3] then writeln(a[k1,3],' ',a[k2,3]) else writeln (a[k2,3],' ',a[k1,3]);
halt;
end;

begin
read(n);
for i:=1 to n do
begin
read(a[i,1],a[i,2]);
a[i,3]:=i;
end;
if n=2 then begin k1:=1;k2:=2;vuv;end;
sort(1,n);

k1:=n div 2;



d:=0;
if a[(n div 2)+1,1]=a[n div 2,1] then k2:=k1+1 else
if a[(n div 2)-1,1]<>a[n div 2,1] then
begin
for i:= 1 to n do
if (i<>k1){ and (a[i,1]<>a[k1,1])} then
begin
s:=abs((a[i,2]-a[k1,2])/(a[i,1]-a[k1,1]));
if s>d then begin d:=s;k2:=i;end;
end;
end else
if k1-1>0 then
begin
k3:=k1-1;
k4:=k1;
for i:=1 to n do
if (i<>k4) and (i<>k3) then
begin
s:=abs((a[i,2]-a[k3,2])/(a[i,1]-a[k3,1]));
if s>d then begin k1:=k3;d:=s;k2:=i;end;
s:=abs((a[i,2]-a[k4,2])/(a[i,1]-a[k4,1]));
if s>d then begin k1:=k4;d:=s;k2:=i;end;
end;

end;
vuv;
end.


thanks for all.

Edited by author 11.08.2006 14:54
Re: who can help me with 7-th test.? thanks
Posted by Nizovtsev Sergey (Lyceum #165) 18 Oct 2006 15:57
Use heapsort
Re: who can help me with 7-th test.? thanks
Posted by PSV 26 Oct 2006 03:37
HeapSort is no necessary. Just sort by angle as you do and take (n div 2 + 1) of them
Re: who can help me with 7-th test.? thanks
Posted by Nizovtsev Sergey (Lyceum #165) 3 Nov 2006 11:10
Try to use heapsort. When I use qsort -> WA6, heapsort -> AC.