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 1020. Rope

Please help me! Why WA????
Posted by Sergey 22 Jun 2003 00:23
my prog:

{$N+}
const nmax = 102;
      p=3.1415926535897932385;
var x,y:array[1..nmax] of real;
    r:extended;
function dist(a,b:byte):extended;
begin dist:=sqrt(sqr(x[b]-x[a])+sqr(y[b]-y[a])); end;
function ugol(a:integer):extended;
var cosa,x1,x2,y1,y2:extended;

begin
  x1:=x[a-1]-x[a];y1:=y[a-1]-y[a];
  x2:=x[a+1]-x[a];y2:=y[a+1]-y[a];
  cosa:=(x1*x2+y1*y2)/(sqrt(sqr(x1)+sqr(y1))*sqrt(sqr(x2)+sqr(y2)));
  if cosa=0 then ugol:=p/2
  else ugol:=arctan(sqrt(1/sqr(cosa)-1));
end;
function duga(a:integer):extended;
begin
  duga:=r*ugol(a);
end;
var i,n:longint;
    s:extended;
begin
readln (n,r);
  for i:=1 to n do
    readln (x[i],y[i]);
x[n+1]:=x[1];y[n+1]:=y[1];
x[n+2]:=x[2];y[n+2]:=y[2];
if n=1 then begin s:=2*p*r; writeln (s:0:2); exit; end;
if n=2 then begin s:=2*p*r+dist(1,2); writeln (s:0:2); exit; end;
  for i:=1 to n do begin
    s:=s+dist(i,i+1);
    s:=s+duga(i+1);
  end;
writeln (s:0:2);
end.
Re: Please help me! Why WA????
Posted by Olympic Bear 27 Jun 2003 22:21
zadacha delaetca gorazdo proshe:

program rope;
var x1,x2,y1,y2,a,b,sum,r:real;
n,i:integer;
begin
sum:=0;
read(n);read(r);
read(x1);read(y1);
a:=x1;b:=y1;
for i:=2 to n do begin
read(x2);read(y2);
sum:=sum+sqrt(sqr(x2-x1)+sqr(y2-y1));
x1:=x2;y1:=y2 end;
sum:=sum+sqrt(sqr(x1-a)+sqr(y1-b));
sum:=sum+2*pi*r;
writeln(sum:1:2)
end.

inace teraetca tochnost !!!
Re: Please help me! Why WA????
Posted by PW 10 Aug 2003 20:37
>Did you start prog with rope=0;