HDU 1140 War on Weather

 

http://acm.hdu.edu.cn/showproblem.php?pid=1140

根据球的切点做简单的判断,一开始找到答案没有跳出循环,各种错。。。

View Code
#include <iostream>

#include <cmath>

using namespace std ;

const double PI=acos(-1.0) ;//π的表示方法 

struct point 

{

    double x,y,z ;

} ;

double dis(point p1,point p2)

{

    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z)) ;

}

int main()

{

    int k,m ;

    while(scanf("%d%d",&k,&m),(k||m))

    {

        point O ;

        O.x=O.y=O.z=0 ;

        point p[101] ;

        for(int i=0;i<k;i++)

            scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z) ;

        double r=20000.0/PI ;

        int ans=0 ;

        while(m--)

        {

            point target ;

            scanf("%lf%lf%lf",&target.x,&target.y,&target.z) ;

            for(int i=0;i<k;i++)

                if(dis(p[i],O)*dis(p[i],O)>=r*r+dis(p[i],target)*dis(p[i],target))

                { 

                    ans++ ;

                    break ;

                }

        }

        printf("%d\n",ans) ;

    }

    return 0 ;

}

 

你可能感兴趣的:(HDU)