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 1173. Lazy Snail

Happy New Year! Russia. Why I get WA? Pelase, help me!!!!!!! [5] // Problem 1173. Lazy Snail 31 Dec 2001 19:02
My program:

Program t1173;{$N+}

Const Eps=1E-20;

Var Snail      :array[0..1000]of record X,Y,W :extended; ID :longint;
Use:boolean end;
    PredW,MinW :extended;
    i,N,CurI,j :longint;

Function GetW(CurX,CurY:extended):extended;
Var CurW,tgW,absW      :extended;
 begin
  if Abs(CurX)<Eps then begin
   if CurY>0 then CurW:=90;
   if CurY<=0 then CurW:=270;
  end else
  if Abs(CurY)<Eps then begin
   if CurX>0 then CurW:=0;
   if CurX<=0 then CurW:=180;
  end else begin
   tgW:=abs(CurY/CurX);
   absW:=ArcTan(tgW)*360/(2*Pi);
   if (CurX>0)and(CurY>0) then CurW:=absW else
   if (CurX>0)and(CurY<0) then CurW:=360-absW else
   if (CurX<0)and(CurY>0) then CurW:=180-absW else
   if (CurX<0)and(CurY<0) then CurW:=180+absW;
  end;
  GetW:=CurW;
 end;

begin
Snail[0].ID:=0;
Read(Snail[0].X,Snail[0].Y);
Read(N);
for i:=1 to N do Read(Snail[i].X,Snail[i].Y,Snail[i].ID);
for i:=1 to N do Snail[i].W:=GetW(Snail[i].X-Snail[0].X,Snail[i].Y-
Snail[0].Y);
for i:=1 to N do Snail[i].Use:=false;
PredW:=361;
Writeln(0);
for j:=1 to N do begin
 MinW:=-1;
 CurI:=0;
 for i:=1 to N do
  if not(Snail[i].Use) then
   if (Snail[i].W>MinW)and(PredW>Snail[i].W) then begin
    MinW:=Snail[i].W;
    CurI:=i;
   end;
 PredW:=MinW;
 Snail[CurI].Use:=true;
 Writeln(Snail[CurI].ID);
end;
Writeln(0);
end.
Michael_Rybak Your solution is almost correct, but... [3] // Problem 1173. Lazy Snail 31 Dec 2001 20:42
there might be some problems with tests like this:
0 0
3
2 0 1
1 1 2
1 -1 3
I think you've caught the idea - we don't know which range should we
choose - from 0 to 2*pi or from -pi to pi or smth... But this bug can
be easily removed. If you still need a hint, email me.
Happy New Year! Russia. Re: Thank you! I get AC. // Problem 1173. Lazy Snail 2 Jan 2002 00:48
Miguel Angel I don't know what you mean :| [1] // Problem 1173. Lazy Snail 3 Jan 2002 12:18
Could you explain with more detailed what's wrong with the test case
you print??
Thanks for all :)
Happy New Year! Russia. Re: I don't know what you mean :| // Problem 1173. Lazy Snail 3 Jan 2002 17:09
If you draw picture for my answer you'll see what's wrong:
     *
     |     | *----|--*
 \   |
  \  |
   \ |
    \|
     *
what about this case

0 0
3
-1 -8 1
-2 -7 2
8 1 3