|
|
back to boardWhy I get WA? Pelase, help me!!!!!!! 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. Your solution is almost correct, but... 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. I don't know what you mean :| Could you explain with more detailed what's wrong with the test case you print?? Thanks for all :) Re: I don't know what you mean :| If you draw picture for my answer you'll see what's wrong: * | | *----|--* \ | \ | \ | \| * Re: Why I get WA? Pelase, help me!!!!!!! Posted by Yuan 15 Mar 2002 11:26 what about this case 0 0 3 -1 -8 1 -2 -7 2 8 1 3 |
|
|