ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1020. Rope

WHY WA ON TEST #4??I am really stuck in this!!!plz help!
Posted by michel mizrahi 11 Apr 2005 05:19
I can't understand what's wrong with my code
is my algorithm wrong? or what?
my code:

#include <stdio.h>
#include <math.h>
double x[102],y[102];

double dist(int i, int j){
int d1=abs(x[i]-x[j]),d2=abs(y[i]-y[j]);
if(d1==0)
return (d2);
else if(d2==0)
return (d1);
else
return sqrt(d1*d1 + d2*d2);
}

int main(){
int i;
double n,s=0,r,pi=2*acos(0);
scanf("%Lf %Lf",&n,&r);
for(i=0;i<n;i++)
scanf("%Lf %Lf",&x[i],&y[i]);
for(i=1;i<n;i++)
s+=dist(i,i-1);
s+=dist(0,n-1);
s+=2*pi*r;
printf("%.2Lf\n",s);
return 0;
}

if someone can help me I would appreciate very much
thanks!
Re: WHY WA ON TEST #4??I am really stuck in this!!!plz help!
Posted by Sandro 11 Apr 2005 08:52
Your algorithm is right. But it seems to me very strange, that d1 and d2 in your code are integers, while x and y are not.

double x[102],y[102];
double dist(int i, int j){
int d1=abs(x[i]-x[j]),d2=abs(y[i]-y[j]);
...}

And double n seems strange to me too.
Re: WHY WA ON TEST #4??I am really stuck in this!!!plz help!
Posted by Cybernetics Team 11 Apr 2005 15:14
Test #4:
3 1.2
12.24 13.34
0.00 24.75
-33.36 70.12

Solution:
153.41
Re: WHY WA ON TEST #4??I am really stuck in this!!!plz help!
Posted by michel mizrahi 12 Apr 2005 09:13
thank you both of you guys :D!!!!!! (and sorry for my bad english :\$)
I finally got ac, just some stupid and silly mistakes!
Re: WHY WA ON TEST #4??I am really stuck in this!!!plz help!
Posted by thamizhkavingan 21 Apr 2019 13:25
the answer should be 149.64 isn't it??? where am I wrong?
Re: WHY WA ON TEST #4??I am really stuck in this!!!plz help!
Posted by Znol 20 Nov 2019 17:27
.

Edited by author 20.11.2019 17:29