Why crash on test #2?! (invalid floating-point operation)
Posted by
Jumbo 21 Mar 2011 01:38
type t=record
x:real;
y:real;
end;
function arccos(a:real):real;
var t:real;
Begin
if a=1 then arccos:=0
else if a=-1 then arccos:=180 else begin
t:=a/sqrt(1-sqr(a));
arccos:=180*((pi/2)-arcTan(t))/pi;
end;
end;
function dlina(x1,y1,x2,y2:real): real;
begin
dlina:=sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
end;
function cos_(x1,y1,x2,y2,x3,y3:real):real;
begin
cos_:=( dlina(x3,y3,x2,y2)*dlina(x3,y3,x2,y2) +
dlina(x1,y1,x2,y2)*dlina(x1,y1,x2,y2) -
dlina(x1,y1,x3,y3)*dlina(x1,y1,x3,y3) ) /
2*dlina(x1,y1,x2,y2)*dlina(x3,y3,x2,y2);
end;
var n,i:integer; x,y,p,cos,r:real; mas:array[1..102] of t;
Begin
readln(n,r);
p:=0;
for i:=1 to n do begin
readln(mas[i].x,mas[i].y);
if i>1 then p:=p+dlina(mas[i-1].x,mas[i-1].y,mas[i].x,mas[i].y);
end;
p:=p+dlina(mas[1].x,mas[1].y,mas[n].x,mas[n].y);
mas[n+1]:=mas[1]; mas[n+2]:=mas[2];
for i:=1 to n do begin
cos:=-cos_(mas[i].x,mas[i].y,mas[i+1].x,mas[i+1].y,mas[i+2].x,mas[i+2].y);
p:=p+arccos(cos)*2*pi*r/360;
end;
writeln(p:1:2);
end.
Edited by author 21.03.2011 01:38