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

Now I have WA#7!
Posted by BlackShark 3 Jan 2009 01:11
var i,j,n,b2,n0,mid:integer;
x,y,al:array[1..10000] of real; num:array[1..10000] of integer;

begin
readln(n);
for i:=1 to n do begin
readln(x[i],y[i]);
num[i]:=i;
end;

n0:=1;
for i:=1 to n do begin
if x[i]<x[n0] then n0:=i;
if (x[i]=x[n0]) and (y[i]<y[n0]) then n0:=i;
end;

for i:=1 to n do
if i<>n0 then begin
if x[i]=x[n0] then al[i]:=pi/2
else al[i]:=arctan((y[i]-y[n0])/(x[i]-x[n0]))
end;

for i:=1 to n-1 do         {Sorting by angle}
for j:=i+1 to n do
if (al[j]<al[i]) and (i<>n0) and (j<>n0) then begin
b2:=num[i]; num[i]:=num[j]; num[j]:=b2; end;

for i:=1 to n div 2 do if i<>n0 then inc(mid) else inc(mid,2);
writeln(num[n0],' ',num[mid]);
end.

Edited by author 05.01.2009 13:11

Edited by author 05.01.2009 13:12
Re: Now I have WA#7!
Posted by BlackShark 5 Jan 2009 13:35
Sorry! I've found a very stupid bug! Now Accepted!!!
Re: Now I have WA#7!
Posted by Oleg Strekalovsky [Vologda SPU] 22 Apr 2009 16:29
I think your algo is O(n^2).
It's strange, that your have not get TLE...