|
|
back to boardDiscussion of Problem 1020. RopeWHY I ALWAYS GET CE???? Posted by ss 27 Jul 2002 09:40 // rope #include <stdio.h> #include <math.h> #include <stdlib.h> #define pi 3.14159265358979 // int N; double Ans,R; double *X; double *Y; double *C; double *Z; double *D; // void Init(void); void Process(void); // void main(void) { Init(); Process(); } // void Init(void) { int i; scanf("%d%lf",&N,&R); X=(double *)malloc((N+2)*sizeof(double)); Y=(double *)malloc((N+2)*sizeof(double)); D=(double *)malloc((N+2)*sizeof(double)); C=(double *)malloc((N+2)*sizeof(double)); Z=(double *)malloc((N+2)*sizeof(double)); for (i=1;i<=N;i++) { scanf("%lf%lf",&X[i],&Y[i]); } X[0]=X[N]; Y[0]=Y[N]; X[N+1]=X[1]; Y[N+1]=Y[1]; } // void Process(void) { int i,j; double alpha1,alpha2; //find Diff for (i=1;i<=N;i++) { D[i]=sqrt(pow((X[i]-X[i+1]),2)+pow((Y [i]-Y[i+1]),2)); } //find Zeta for (i=1;i<=N;i++) { alpha1=atan2(abs(Y[i+1]-Y[i]),abs(X [i+1]-X[i])); alpha2=atan2(abs(Y[i]-Y[i-1]),abs(X[i]- X[i-1])); Z[i]=pi-(alpha1+alpha2); } //find Curve for (i=1;i<=N;i++) { C[i]=Z[i]*R; } //find sum Answer Ans=0; for (i=1;i<=N;i++) { Ans+=D[i]+C[i]; } printf("%.2lf\n",Ans); } Your program will show Domain Error for some cases, for atan2( ). Fix it. :) Re: WHY I ALWAYS GET CE???? Posted by Madhav 15 Jun 2008 15:09 The return type of main is int not void. |
|
|