题意:三维空间里面有n颗星星,另有m个望远镜,朝向与张角知道了,问能看到多少个星星。
题解:算出每个星星与望远镜朝向的夹角,在与望远镜张角比较一下便知道能否看到了。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 using namespace std; 6 const double eps=1e-8,pi=acos(-1.0); 7 struct point 8 { 9 double x,y,z; 10 }po[600]; 11 double dmult(point a,point b) 12 { 13 return a.x*b.x+a.y*b.y+a.z*b.z; 14 } 15 double getm(point a) 16 { 17 return sqrt(a.x*a.x+a.y*a.y+a.z*a.z); 18 } 19 int main() 20 { 21 int n,m; 22 while(scanf("%d",&n),n) 23 { 24 for(int i=0;i<n;i++) 25 scanf("%lf%lf%lf",&po[i].x,&po[i].y,&po[i].z); 26 scanf("%d",&m); 27 bool vis[600]; 28 memset(vis,false,sizeof(vis)); 29 point p; 30 double th; 31 int cnt=0; 32 for(int i=0;i<m;i++) 33 { 34 scanf("%lf%lf%lf%lf",&p.x,&p.y,&p.z,&th); 35 for(int j=0;j<n;j++) 36 { 37 if(!vis[j]) 38 { 39 if(acos(dmult(p,po[j])/getm(p)/getm(po[j]))-th<eps) 40 { 41 cnt++; 42 vis[j]=true; 43 } 44 } 45 } 46 } 47 printf("%d\n",cnt); 48 } 49 return 0; 50 }