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

My program works right, please check it, or give me some tests please
Posted by Redjee 9 May 2010 19:46
type
    point=record x,y:longint; end;
var
    vert:array[1..10000] of point;
    visited:array[1..10000] of byte;
    min:point;
    n,i,k,imin,minvert:integer;
Procedure Search_Min_Polar_Angle;
var
    i:integer;
    min_angle,angle,tg,a,b:real;
begin
    min_angle:=pi;
    for i:=1 to n do
        if (visited[i]=0) then
            begin
                a:=(vert[i].y-vert[imin].y);
                b:=(vert[i].x-vert[imin].x);
                if (b=0) then angle:=pi/2
                         else
                begin
                    tg:=a/b;
                    angle:=arctan(tg);
                end;
                if (angle<min_angle) then
                    begin min_angle:=angle; minvert:=i; end;
            end;
    visited[minvert]:=1;
end;

Begin
    readln(n);
    for i:=1 to n do visited[i]:=0;

    // naxojdenie samoy nijney levoy to4ki
    min.y:=maxlongint;
    for i:=1 to n do
        begin
            readln(vert[i].x,vert[i].y);
            if (vert[i].y<min.y) then
                begin min:=vert[i]; imin:=i; end
            else
            if (vert[i].y=min.y) and (vert[i].x<min.x) then
                begin min:=vert[i]; imin:=i; end;
        end;
    visited[imin]:=1;
    //-----------------------------------

    for k:=1 to n div 2 do Search_Min_Polar_Angle;
    writeln(imin,' ',minvert);
End.

Edited by author 09.05.2010 19:47