hdu 2436 判断长方体与球是否相交
长方体与球相交则必然是长方体中离球最近的点在球面上或球内,而长方体离球最近点必是每一维中离球最近的坐标组成的点。
/*
* hdu2436/linux.cpp
* Created on: 2011-8-28
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long I64;
void work();
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
work();
return 0;
}
inline int getm(int M, int m0, int m7) {
int ret = M;
if (M > m7) {
ret = m7;
} else if (M < m0) {
ret = m0;
}
return ret;
}
inline I64 distance2(I64 x0, I64 y0, I64 z0, I64 x1, I64 y1, I64 z1) {
return (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1) + (z0 - z1) * (z0 - z1);
}
void work() {
int T, i;
int x[8], y[8], z[8];
int X, Y, Z, R;
int mx, my, mz;
scanf("%d", &T);
while (T--) {
for (i = 0; i < 8; i++) {
scanf("%d%d%d", &x[i], &y[i], &z[i]);
}
scanf("%d%d%d%d", &X, &Y, &Z, &R);
sort(x, x + 8);
sort(y, y + 8);
sort(z, z + 8);
mx = getm(X, x[0], x[7]);
my = getm(Y, y[0], y[7]);
mz = getm(Z, z[0], z[7]);
if (distance2(X, Y, Z, mx, my, mz) <= (I64) R * R) {
puts("Yes");
} else {
puts("No");
}
}
}