I need to use atan(), that is in <math.h>. How can i complie a problem (i mean on the judge system) using the -lm option?.
thanks
Need to use atan
Moderator: Board moderators
I know about atan2, that was what i were actually using. I included <math.h>, but i awlys get compilation error. With my version of gcc, i don't. Can anyone tell me why this source gets compliation error?:
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define nmax 10005
FILE *fin,*fout;
long c,n;
double sx,sy;
struct point
{
long x,y;
double f;
};
typedef struct point point;
struct point h[nmax];
int comp(const void *aa,const void *bb)
{
point a,b;
a=*(point *)aa;
b=*(point *)bb;
if (b.f-a.f>0) return -1;
else if (b.f-a.f<0) return 1;
else
{
if ((a.x>sx)||((a.x==sx)&&(a.y>sy)))
{
if ((a.x-sx)*(a.x-sx)+(a.y-sy)*(a.y-sy)>(b.x-sx)*(b.x-sx)+(b.y-sy)*(b.y-sy)) return 1;
else return -1;
}
else
{
if ((a.x-sx)*(a.x-sx)+(a.y-sy)*(a.y-sy)>(b.x-sx)*(b.x-sx)+(b.y-sy)*(b.y-sy))
{
return 1;
}
else
{
return -1;
}
}
}
}
int n_egal(double x,double y)
{
if ((long)x!=(long)y) return 1;
else
{
x-=(long)x;
y-=(long)y;
return (long)(x*1000000)!=(long)(y*1000000);
}
}
int main()
{
long i,j;
scanf("%ld",&c);
while (c)
{
c--;
scanf("%ld",&n);
for (i=0;i<n;i++) scanf("%ld %ld",&h.x,&h.y);
sx=0;
sy=0;
for (i=0;i<n;i++) { sx+=(double)h.x/n; sy+=(double)h.y/n; }
for (i=0;i<n;i++) if ((!n_egal((double)h.x,sx))&&(!n_egal((double)h.y,sy)))
{
for (j=i;j<n;j++) h[j]=h[j+1];
n--;
}
if (n%2) printf("no\n");
else
{
for (i=0;i<n;i++)
{
h.f=atan2(h.y-sy,h.x-sx);
if (h.f<0) h[i].f+=2*M_PI;
}
qsort(h,n,sizeof(h[0]),comp);
for (i=0;i<n/2;i++)
{
if (n_egal(sx,((double)h[i].x+h[i+n/2].x)/2))
{
if (n_egal(sy,((double)h[i].y+h[i+n/2].y)/2))
{
i=-1;
break;
}
}
}
if (i==-1) printf("no\n");
else printf("yes\n");
}
}
return 0;
}
Thanks.
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define nmax 10005
FILE *fin,*fout;
long c,n;
double sx,sy;
struct point
{
long x,y;
double f;
};
typedef struct point point;
struct point h[nmax];
int comp(const void *aa,const void *bb)
{
point a,b;
a=*(point *)aa;
b=*(point *)bb;
if (b.f-a.f>0) return -1;
else if (b.f-a.f<0) return 1;
else
{
if ((a.x>sx)||((a.x==sx)&&(a.y>sy)))
{
if ((a.x-sx)*(a.x-sx)+(a.y-sy)*(a.y-sy)>(b.x-sx)*(b.x-sx)+(b.y-sy)*(b.y-sy)) return 1;
else return -1;
}
else
{
if ((a.x-sx)*(a.x-sx)+(a.y-sy)*(a.y-sy)>(b.x-sx)*(b.x-sx)+(b.y-sy)*(b.y-sy))
{
return 1;
}
else
{
return -1;
}
}
}
}
int n_egal(double x,double y)
{
if ((long)x!=(long)y) return 1;
else
{
x-=(long)x;
y-=(long)y;
return (long)(x*1000000)!=(long)(y*1000000);
}
}
int main()
{
long i,j;
scanf("%ld",&c);
while (c)
{
c--;
scanf("%ld",&n);
for (i=0;i<n;i++) scanf("%ld %ld",&h.x,&h.y);
sx=0;
sy=0;
for (i=0;i<n;i++) { sx+=(double)h.x/n; sy+=(double)h.y/n; }
for (i=0;i<n;i++) if ((!n_egal((double)h.x,sx))&&(!n_egal((double)h.y,sy)))
{
for (j=i;j<n;j++) h[j]=h[j+1];
n--;
}
if (n%2) printf("no\n");
else
{
for (i=0;i<n;i++)
{
h.f=atan2(h.y-sy,h.x-sx);
if (h.f<0) h[i].f+=2*M_PI;
}
qsort(h,n,sizeof(h[0]),comp);
for (i=0;i<n/2;i++)
{
if (n_egal(sx,((double)h[i].x+h[i+n/2].x)/2))
{
if (n_egal(sy,((double)h[i].y+h[i+n/2].y)/2))
{
i=-1;
break;
}
}
}
if (i==-1) printf("no\n");
else printf("yes\n");
}
}
return 0;
}
Thanks.