#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
const int maxn = 305;
const double eps = 1e-6;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
struct Point {
double x, y, z;
void read() {
scanf("%lf%lf%lf", &x, &y, &z);
}
Point(double x = 0, double y = 0, double z = 0) :
x(x), y(y), z(z) {
}
double operator *(const Point& t) const {
return x * t.x + y * t.y + z * t.z;
}
Point operator ^(const Point& t) const {
return Point(y * t.z - t.y * z, z * t.x - t.z * x, x * t.y - t.x * y);
}
Point operator -(const Point& t) const {
return Point(x - t.x, y - t.y, z - t.z);
}
Point operator +(const Point& t) const {
return Point(x + t.x, y + t.y, z + t.z);
}
double norm() {
return sqrt(x * x + y * y + z * z);
}
void unit() {
double t = this->norm();
x /= t;
y /= t;
z /= t;
}
double dis(const Point& t) const {
double a, b, c;
a = x - t.x;
b = y - t.y;
c = z - t.z;
return sqrt(a * a + b * b + c * c);
}
};
int dblcmp(double x) {
if (x < -eps)
return -1;
return x > eps;
}
Point center[maxn];
Point A[maxn], B[maxn];
Point u[maxn], v[maxn], dir[maxn];
double radius[maxn];
double cal(int p, int q) {
Point tmp = center[p] - center[q];
Point n = dir[p] ^ dir[q];
n.unit();
return fabs(n * tmp);
}
bool solve(int n, double& ans) {
int i, j;
double d, p;
ans = 1e50;
for (i = 0; i < n; ++i) {
for (j = i + 1; j < n; ++j) {
d = radius[i] + radius[j];
p = cal(i, j);
if (dblcmp(p - d) <= 0) {
return true;
} else
ans = min(ans, p - d);
}
}
return false;
}
int main() {
int n, i;
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (i = 0; i < n; ++i) {
center[i].read();
A[i].read();
B[i].read();
u[i] = A[i] - center[i];
v[i] = B[i] - center[i];
dir[i] = u[i] ^ v[i];
radius[i] = center[i].dis(A[i]);
}
double ans;
bool flag = solve(n, ans);
if (flag)
puts("Lucky");
else {
printf("%.2f\n", ans);
}
}
return 0;
}
HDU 4617
最新推荐文章于 2019-10-01 10:52:28 发布