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

Common Board

Problem 1232. Why I get WA?
Posted by Need For Success (Denis Nazarov) 14 Nov 2002 22:52
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.