WA #2 help!
Posted by
akash 18 Dec 2010 13:23
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>
int cal(double x1, double y1, double x2, double y2){
int d;
d=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
return d;
}
int main(){
int no_of_nails,j;
double radius;
double total_length=0;
double x1,y1,x2,y2;
double nextx,nexty,prevx,prevy;
fscanf(stdin, "%d %lf",&no_of_nails,&radius);
getchar();
total_length += no_of_nails * ((M_PI*radius)/2);
if(no_of_nails==1) {
total_length += M_PI*2*radius;
printf("%0.2lf",total_length);
return 0;
}
fscanf(stdin,"%lf %lf",&x1,&y1);
fscanf(stdin,"%lf %lf",&x2,&y2);
total_length+=cal(x1,y1,x2,y2);
prevx=x2;
prevy=y2;
if(no_of_nails>2){
for(j=no_of_nails-2;j>0;j--){
fscanf(stdin,"%lf %lf",&nextx,&nexty);
total_length += cal(prevx,prevy,nextx,nexty);
prevx=nextx;
prevy=nexty;
}
total_length += cal(prevx,prevy,x1,y1);
}
printf("%0.2lf",total_length);
return 0;
}