大意:地球球心是(0,0,0),给你k个卫星以及k个卫星的三维坐标(以球心为基准),m个地球上的点以及m个点的三维坐标(以球心为基准),问有多少个点是能被卫星覆盖到的,输出数量。
思路:
求出卫星与地球切线的长度,在地球上,与卫星连线的长度小于切线长度的肯定都能看到。
#define pi acos(-1.0) struct point { double x, y, z; } P[110]; double distance(point a, point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z); } int n, m; void Solve() { double R = 20000.0/pi; while(~scanf("%d%d", &n, &m)) { if(!n && !m) { break; } for(int i = 0; i < n; ++i) { scanf("%lf%lf%lf", &P[i].x, &P[i].y, &P[i].z); } int cnt = 0; point pp; for(int i = 0; i < m; ++i) { scanf("%lf%lf%lf", &pp.x, &pp.y, &pp.z); for(int j = 0; j < n; ++j) { double D2 = P[j].x*P[j].x+P[j].y*P[j].y+P[j].z*P[j].z; double L2 = D2-R*R; if(distance(P[j], pp) <= L2) { cnt++; break; } } } printf("%d\n", cnt); } }
HDU 1140 War on Weather (三维点之间距离),布布扣,bubuko.com
HDU 1140 War on Weather (三维点之间距离)
原文:http://blog.csdn.net/xuechelingxiao/article/details/23822709