Poj Solution 3129

http://poj.org/problem?id=3129

#include <stdio.h>
#include <math.h>


struct point {
    double x, y, z;
};

double dcheng( point &a, point &b ) {
    return a.x*b.x+a.y*b.y+a.z*b.z;
}

point p[500], q[50];
double r[50];

int main( ) {
    int i, j, n, m, counter;
    double t;
    while( scanf( "%d", &n ) == 1 && n ) {
        for( i=0; i<n; i++ )
            scanf( "%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z );
        scanf( "%d", &m );
        for( i=0; i<m; i++ )
            scanf( "%lf%lf%lf%lf", &q[i].x, &q[i].y, &q[i].z, &r[i] );

        counter = 0;
        for( i=0; i<n; i++ ) {
            t = dcheng(p[i],p[i]);
            for( j=0; j<m; j++ ) {
                if( acos( dcheng( p[i], q[j] )/sqrt(t*dcheng(q[j],q[j])) ) < r[j] )
                    break;
            }
            if( j < m )
                counter++;
        }
        printf( "%dn", counter );
    }
    return 0;
}
											
This entry was posted in poj. Bookmark the permalink.