HDU 4617

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值