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

COMPILATION ERROR !!! please HELP
Posted by Damboiu Mihai 14 Oct 2002 01:00
Please tell me where is the compilation error !
#include<stdio.h>
#include<math.h>
#define TG(x1,y1,x2,y2) ((y2)-(y1))/((x2)-(x1))
#define EUCLID(x1,y1,x2,y2)\
 sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
#define INFINIT 100000
#define MAX 102
struct POINT
    {float x,y;};
int N,i;
float R,rope,m1,m2,m,rad;
struct POINT p[MAX];
void main(void)
 {
  scanf("%d%f",&N,&R);
  for(i=0;i<N;i++)
   scanf("%f%f",&p[i].x,&p[i].y);
  p[N]=p[0];
  p[N+1]=p[1];
  switch (N)
   { case 1 : {rope=2*M_PI*R;break;}
     case 2 : {rope=2*M_PI*R+2*EUCLID(p[0].x,p[0].y,p[1].x,
p[1].y);break;}
     default : {
    rope=0.0;
    if (p[0].x!=p[1].x)
      m1=TG(p[0].x,p[0].y,p[1].x,p[1].y);
    else
    m1=INFINIT;
    for(i=1;i<=N;i++)
     { rope+=EUCLID(p[i].x,p[i].y,p[i+1].x,p[i+1].y);
       if (p[i].x!=p[i+1].x)
        m2=TG(p[i].x,p[i].y,p[i+1].x,p[i+1].y);
       else
        m2=INFINIT;
       if (fabs(m2-m1)==INFINIT)
        rad=M_PI_2;
       else
        {
         if (m1==INFINIT && m2!= INFINIT)
          m= -1.00/m2;
         else if (m2==INFINIT && m1!= INFINIT)
           m=1.00/m1;
         else
          m=(m2-m1)/(1+m1*m2);
         rad=atan(m);
         if (rad<=0)
          rad+=M_PI;
        }/*else*/
      rope+=R*rad;
      m1=m2;
      }/*for*/
      }/* default*/
     }/*switch*/
   printf("%.2f",rope);
   }/*main*/