|
|
back to boardCommon BoardProblem 1232. Why I get WA? What's wrong with a such solution? Program p1232; {$N+} Const Eps = 1e-12; Type Point = Record X,Y,Z : Extended End; Var h,d,alpha : Extended; Ans : Array[0..1500]of Point; Function IsCPoint(P : Point) : Boolean; Var CurH,MaxD : Extended; begin CurH:=h-P.Z; MaxD:=CurH*Sin(alpha/2)/Cos(alpha/2); IsCPoint:=Abs(P.X)<MaxD+Eps; end; Function CanLPoint(HD : Extended; LP : Point; Var NP : Point) : Boolean; begin NP.Y:=0; NP.Z:=LP.Z-HD; NP.X:=LP.X-sqrt(d*d-HD*HD); CanLPoint:=IsCPoint(NP); end; Function CanRPoint(HD : Extended; LP : Point; Var NP : Point) : Boolean; begin NP.Y:=0; NP.Z:=LP.Z-HD; NP.X:=LP.X+sqrt(d*d-HD*HD); CanRPoint:=IsCPoint(NP); end; Procedure TryIt; Var n,i : Integer; curh,need : Extended; L,R,M : Extended; GLeft,GDown : Boolean; begin n:=Trunc(1+h/d-Eps); if d-Eps>h/Cos(alpha/2) then Exit; ans[0].X:=0; for i:=0 to n do ans[i].Y:=0; ans[0].Z:=h; GLeft:=True; GDown:=False; if (n*d+Eps>h) And (n*d-Eps<h) then GDown:=True; for i:=1 to n do begin if GDown then begin ans[i].X:=ans[i-1].X; ans[i].Z:=ans[i-1].Z-d; Continue; end; need:=ans[i-1].Z-(n-i)*d; if GLeft then begin L:=1e-7; R:=d; if R>ans[i-1].Z then R:=ans[i-1].Z; While R-L>Eps Do begin M:=(R+L)/2; if CanLPoint(M,ans[i-1],ans[i]) then R:=M else L:=M; end; if M<need then begin M:=need; GDown:=True; end; if Not CanLPoint(M,ans[i-1],ans[i]) then Exit; GLeft:=False; end else begin L:=1e-7; R:=d; if R>ans[i-1].Z then R:=ans[i-1].Z; While R-L>Eps Do begin M:=(R+L)/2; if CanRPoint(M,ans[i-1],ans[i]) then R:=M else L:=M; end; if M<need then begin M:=need; GDown:=True; end; if Not CanRPoint(M,ans[i-1],ans[i]) then Exit; GLeft:=True; end; end; Writeln(n); for i:=1 to n do Writeln(Ans[i].X:0:8,' ',Ans[i].Y:0:8,' ',Abs(Ans [i].Z):0:8); Halt; end; begin Read(h,d,alpha); TryIt; Writeln(-1); end. |
|
|