HDU 4617 Weapon(三维几何)
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL; const double EPS = 1e-;
const double INF = 1e50;
const double PI = acos(-1.0); inline int sgn(double x) {
return (x > EPS) - (x < EPS);
} struct Point3D {
double x, y, z;
Point3D() {}
Point3D(double x, double y, double z): x(x), y(y), z(z) {}
void read() {
scanf("%lf%lf%lf", &x, &y, &z);
}
double operator * (const Point3D &rhs) const {
return x * rhs.x + y * rhs.y + z * rhs.z;
}
Point3D operator + (const Point3D &rhs) const {
return Point3D(x + rhs.x, y + rhs.y, z + rhs.z);
}
Point3D operator - (const Point3D &rhs) const {
return Point3D(x - rhs.x, y - rhs.y, z - rhs.z);
}
double length() const {
return sqrt(x * x + y * y + z * z);
}
}; struct Line3D {
Point3D st, ed;
Line3D() {}
Line3D(Point3D st, Point3D ed): st(st), ed(ed) {}
}; struct Plane3D {
Point3D a, b, c;
Plane3D() {}
Plane3D(Point3D a, Point3D b, Point3D c): a(a), b(b), c(c) {}
void read() {
a.read(), b.read(), c.read();
}
}; double dist(const Point3D &a, const Point3D &b) {
return (a - b).length();
}
//叉积
Point3D cross(const Point3D &u, const Point3D &v) {
Point3D ret;
ret.x = u.y * v.z - u.z * v.y;
ret.y = u.z * v.x - u.x * v.z;
ret.z = u.x * v.y - u.y * v.x;
return ret;
}
//点到直线距离
double point_to_line(const Point3D &p, const Line3D &l) {
return cross(p - l.st, l.ed - l.st).length() / dist(l.ed, l.st);
}
//求两直线间的距离
double line_to_line(const Line3D u, const Line3D v) {
Point3D n = cross(u.ed - u.st, v.ed - v.st);
return fabs((u.st - v.st) * n) / n.length();
}
//取平面法向量
Point3D vector_of_plane(const Plane3D &s) {
return cross(s.a - s.b, s.b - s.c);
}
//判断两直线是否平行
bool isParallel(const Line3D &u, const Line3D &v) {
return sgn(cross(u.ed - u.st, v.ed - v.st).length()) <= ;
} const int MAXN = ; Plane3D s[MAXN];
Line3D l[MAXN];
double r[MAXN];
int T, n; int main() {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = ; i < n; ++i) s[i].read();
for(int i = ; i < n; ++i) {
Point3D v = vector_of_plane(s[i]);
l[i] = Line3D(s[i].a, s[i].a + v);
r[i] = dist(s[i].a, s[i].b);
}
double ans = INF;
for(int i = ; i < n; ++i) {
for(int j = i + ; j < n; ++j) {
double d;
if(isParallel(l[i], l[j])) d = point_to_line(l[i].st, l[j]);
else d = line_to_line(l[i], l[j]);
ans = min(ans, d - r[i] - r[j]);
}
}
if(sgn(ans) <= ) puts("Lucky");
else printf("%.2f\n", ans);
}
}
HDU 4617 Weapon(三维几何)的更多相关文章
- HDU 4617 Weapon 三维计算几何
		
题意:给你一些无限长的圆柱,知道圆柱轴心直线(根据他给的三个点确定的平面求法向量即可)与半径,判断是否有圆柱相交.如果没有,输出柱面最小距离. 一共只有30个圆柱,直接暴力一下就行. 判相交/相切:空 ...
 - hdu 4617 Weapon【异面直线距离——基础三维几何】
		
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others) ...
 - hdu 4617 Weapon
		
http://acm.hdu.edu.cn/showproblem.php?pid=4617 三维几何简单题 多谢高尚博学长留下的模板 代码: #include <iostream> #i ...
 - HDU 4617 Weapon (简单三维计算几何,异面直线距离)
		
Weapon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
 - hdu 4617 Weapon(叉积)
		
大一学弟表示刚学过高数,轻松无压力. 我等学长情何以堪= = 求空间无限延伸的两个圆柱体是否相交,其实就是叉积搞一搞 详细点就是求两圆心的向量在两直线(圆心所在的直线)叉积上的投影 代码略挫,看他的吧 ...
 - hdu 5839(三维几何)
		
Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
 - POJ 3528--Ultimate Weapon(三维凸包)
		
Ultimate Weapon Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 2430 Accepted: 1173 ...
 - HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)
		
HDU - 3584 Cube Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Subm ...
 - HDU 3584 Cube --三维树状数组
		
题意:给一个三维数组n*n*n,初始都为0,每次有两个操作: 1. 翻转(x1,y1,z1) -> (x2,y2,z2) 0. 查询A[x][y][z] (A为该数组) 解法:树状数组维护操作次 ...
 
随机推荐
- hashMap 和 linkedHashMap 的区别和联系
			
直接举例说明. 运行如下例子程序 mport java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; ...
 - React通过dva-model-extend实现 dva 动态生成 model
			
前言 实现通过单个component 单个router通过相应的标识对应产生不同model实现数据包分离,model namespce将会覆盖基础的Model,其中的model[state|subsc ...
 - 常用模块 - datetime模块
			
一.简介 datetime是Python处理日期和时间的标准库. 1.datetime模块中常用的类: 类名 功能说明 date 日期对象,常用的属性有year, month, day time 时间 ...
 - java实现验证码功能主要代码
			
package com.baojuan.servlet; import java.awt.Color;import java.awt.Font;import java.awt.Graphics2D;i ...
 - jdk11新特性
			
JDK 11主要特性一览 jdk11即将在9月25号发布正式版.确定的新特性包括以下17个 181 嵌套类可见性控制 309 动态文件常量 315 改进 Aarch64 Intrinsics 318 ...
 - layui   sleect获取value值
			
<div class="layui-form-item"> <label for="username" class="layui-f ...
 - 20190118-自定义实现replace方法
			
1.自定义实现replace方法 Python replace() 方法把字符串中的 old(旧字符串) 替换成 neange(新字符串),如果指定第三个参数max,则替换不超过 max 次.考虑ol ...
 - hadoop 1.x 集群环境的搭建
			
本文主要以个人工作学习总结为主,同时也为了方便更多的兴趣爱好者参与学习交流,现将具体的搭建步骤分享如下: 一.基础环境 1.1 jdk的安装与配置 Hadoop是用Java开发的,Hadoop的编译及 ...
 - [BZOJ4552][Tjoi2016&Heoi2016]排序(二分答案+线段树)
			
二分答案mid,将>=mid的设为1,<mid的设为0,这样排序就变成了区间修改的操作,维护一下区间和即可 然后询问第q个位置的值,为1说明>=mid,以上 时间复杂度O(nlog2 ...
 - 利用cross-entropy cost代替quadratic cost来获得更好的收敛
			
1.从方差代价函数说起(Quadratic cost) 代价函数经常用方差代价函数(即采用均方误差MSE),比如对于一个神经元(单输入单输出,sigmoid函数),定义其代价函数为: 其中y是我们期望 ...