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 1215. Exactness of Projectile Hit

why wa2?I have tried many tests,and output the right answer,but WA2
Posted by uuu 1 Sep 2010 20:20

 var
  i,j,k,n,m,tot:longint;
  ans,x1,y1,x2,y2,d1,d2,d3,x,y,angle1,angle2,t,p1,p2:double;

 function min(xx,yy:double):double;
  begin
   if xx>yy then exit(yy);
   exit(xx);
  end;

 begin
  {assign(input,'1215.in');reset(input);}
  read(x,y,n);
  read(x1,y1);
  p1:=x1;
  p2:=y1;
  d1:=sqrt(sqr(x-x1)+sqr(y-y1));
  ans:=999999999;
  tot:=0;
  for i:=2 to n do
   begin
    read(x2,y2);
    if (x1<x)and(x2>=x)and((y1<y)or(y2<y))
     then
      inc(tot);
    d2:=sqrt(sqr(x-x2)+sqr(y-y2));
    d3:=sqrt(sqr(x1-x2)+sqr(y1-y2));
    angle1:=(d2*d2+d3*d3-d1*d1)/(2*d2*d3);
    angle2:=(d1*d1+d3*d3-d2*d2)/(2*d1*d3);
    if (angle1>=0)and(angle2>=0)
     then
      begin
       if x1=x2
        then
         t:=abs(x1-x)
        else
         t:=((y1-y2)/(x1-x2)*x-y+y1+(y2-y1)/(x1-x2)*x1)/(sqrt(sqr((y1-y2)/(x1-x2))+1));
       t:=abs(t);
       ans:=min(ans,t);
      end
     else
      begin
       t:=min(d1,d2);
       ans:=min(ans,t);
      end;
    d1:=d2;
    x1:=x2;
    y1:=y2;
   end;
  x2:=p1;
  y2:=p2;
  if (x1<x)and(x2>=x)and((y1<y)or(y2<y))
     then
      inc(tot);
    d2:=sqrt(sqr(x-x2)+sqr(y-y2));
    d3:=sqrt(sqr(x1-x2)+sqr(y1-y2));
    angle1:=(d2*d2+d3*d3-d1*d1)/(2*d2*d3);
    angle2:=(d1*d1+d3*d3-d2*d2)/(2*d1*d3);
    if (angle1>=0)and(angle2>=0)
     then
      begin
       if x1=x2
        then
         t:=abs(x1-x)
        else
         t:=((y1-y2)/(x1-x2)*x-y+y1+(y2-y1)/(x1-x2)*x1)/(sqrt(sqr((y1-y2)/(x1-x2))+1));
       t:=abs(t);
       ans:=min(ans,t);
      end
     else
      begin
       t:=min(d1,d2);
       ans:=min(ans,t);
      end;
  if odd(tot)
   then
    ans:=0;
  writeln(ans*2:0:3);
 end.