题目大意:空间中有许多无限长的棒子(圆柱体),求棒子间最小距离。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; const double eps = 1e-;
struct Point3//三维空间点
{
double x, y, z;
Point3(double x=,double y=,double z=): x(x),y(y),z(z){}
Point3 operator + (Point3 &t){return Point3(x+t.x, y+t.y, z+t.z);}
Point3 operator - (Point3 &t) {return Point3(x-t.x, y-t.y, z-t.z);}
Point3 operator * (double p) {return Point3(x*p, y*p, z*p);}
Point3 operator / (double p) {return Point3(x/p, y/p, z/p);}
};
typedef Point3 Vector3;
struct Line//空间直线
{
Point3 a,b;
};
int dcmp(double x)
{
if(fabs(x) < eps) return ;
return x < ? - : ;
}
double Dot(Vector3 A,Vector3 B) { return A.x*B.x + A.y*B.y + A.z*B.z; }
double Length2(Vector3 A) { return Dot(A, A); }
Vector3 Cross(Vector3 A, Vector3 B) { return Vector3(A.y*B.z - A.z*B.y, A.z*B.x - A.x*B.z, A.x*B.y - A.y*B.x); }
inline double min(double a,double b)
{
if(dcmp(b-a)>=) return a;
return b;
}
double LineToLine(Line u,Line v)//空间直线间距离
{
Vector3 t=Cross(u.a-u.b,v.a-v.b);
return fabs(Dot(u.a-v.a,t))/sqrt(Length2(t));
} Line L[];
double R[]; void init(int i)
{
Point3 a,b,c;
scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.z,&b.x,&b.y,&b.z,&c.x,&c.y,&c.z);
Vector3 n=Cross(b-a,c-a);//平面法向量
L[i].a=a;L[i].b=a+n;R[i]=sqrt(Length2(b-a));
} int main()
{
int T,i,j,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<n;i++) init(i);
bool flag=;
double ans=1e20;
for(i=;i<n&&!flag;i++)
{
for(j=i+;j<n&&!flag;j++)
{
double temp=LineToLine(L[i],L[j]);
if(dcmp(R[i]+R[j]-temp)>=)
flag=;
else ans=min(ans,temp-R[i]-R[j]);
}
}
if(flag) printf("Lucky\n");
else printf("%.2lf\n",ans);
}
return ;
}

hdu 4671 异面直线的距离的更多相关文章

  1. HDU 4617Weapon(两条异面直线的距离)

    Weapon Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Sub ...

  2. hdu 4741 Save Labman No.004 (异面直线的距离)

    转载学习: #include <cstdio> #include <cstdlib> #include <cstring> #include <algorit ...

  3. HDU 4741 Save Labman No.004 (2013杭州网络赛1004题,求三维空间异面直线的距离及最近点)

    Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. Hdu 4312-Meeting point-2 切比雪夫距离,曼哈顿距离,前缀和

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4312 Meeting point-2 Time Limit: 2000/1000 MS (Java/Ot ...

  5. Hdu 4311-Meeting point-1 曼哈顿距离,前缀和

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4311 Meeting point-1 Time Limit: 2000/1000 MS (Java/Oth ...

  6. HDU 4666 Hyperspace(曼哈顿距离)

    题目链接 这是HDU第400个题. #include <cstdio> #include <cstring> #include <set> #include < ...

  7. hdu 4666 最大曼哈顿距离

    思路:这题我是看了题目后,上百度搜了一下才知道还有求最大曼哈顿距离的方法.直接把代码copy过来,研读一下,知道了代码实现机制,自然就很容易想到用优先队列来维护每种状态下的xi,yi之和的最大值最小值 ...

  8. HDU - 3567 IDA* + 曼哈顿距离 + 康托 [kuangbin带你飞]专题二

    这题难度颇大啊,TLE一天了,测试数据组数太多了.双向广度优先搜索不能得到字典序最小的,一直WA. 思路:利用IDA*算法,当前状态到达目标状态的可能最小步数就是曼哈顿距离,用于搜索中的剪枝.下次搜索 ...

  9. HDU 4671 Partition(定理题)

    题目链接 这题,明显考察搜索能力...在中文版的维基百科中找到了公式. #include <cstdio> #include <cstring> #include <st ...

随机推荐

  1. RuntimeError: cryptography is required for sha256_password or caching_sha2_p

    报错原因:mysql版本身份验证出现问题引起的 我这里报错的地方是在Django里,pycharm连接数据库时出现的 解决办法,安装安装cryptography即可:pip install crypt ...

  2. VueX源码分析(1)

    VueX源码分析(1) 文件架构如下 /module /plugins helpers.js index.esm.js index.js store.js util.js util.js 先从最简单的 ...

  3. BZOJ-3679(数位DP)

    #include <bits/stdc++.h> using namespace std; typedef long long ll; ll a,b; int k[20]; ll dp[2 ...

  4. matplotlib绘图股票走势图实践

    导入模块 import pandas as pdimport numpy as npfrom pandas import Series,DataFrameimport matplotlib.pyplo ...

  5. node 文件下载到本地 (支持中文文件名)

    downloadfile:function(req,res,next){ var name= encodeURI(req.query.name); var path= req.query.url; v ...

  6. python 数据结构与算法之排序(冒泡,选择,插入)

    目录 数据结构与算法之排序(冒泡,选择,插入) 为什么学习数据结构与算法: 数据结构与算法: 算法: 数据结构 冒泡排序法 选择排序法 插入排序法 数据结构与算法之排序(冒泡,选择,插入) 为什么学习 ...

  7. python-函数基础、函数参数

    目录 函数的基础 什么是函数 为何用函数 如何调用函数 定义函数的三种形式 无参函数 有参函数 空函数 函数的返回值 什么是返回值 为什么要有返回值 函数的调用 函数参数的应用 形参和实参 位置参数 ...

  8. jsp常用动作

    jsp:include 动态包含: jsp:forward 转发: jsp:useBean 实例化bean对象: jsp:setProperty 设置一个属性值 jsp:getProperty 获取一 ...

  9. python3 连接 mysql和mariadb的模块

    是pymysql python2中是MySQL-python sudo pip install pymysql 参考博客https://www.jb51.net/article/140387.htm

  10. graph-Dijkstra's shortest-path alogorithm

    直接贴代码吧,简明易懂. 后面自己写了测试,输入数据为: a b c d e 0 1 4 0 2 2 1 2 3 1 3 2 1 4 3 2 1 1 2 3 4 2 4 5 4 3 1 也就是课本上1 ...