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

 #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. cocos2dx 字体描边遇到的描边缺失的bug

    在cocos中,设置字体描边可以用enableOutline(cc.c4b(30, 10, 0, 255), 2)函数设置,第一个参数是字体颜色,第二个参数是描边轮廓大小,单位是2个像素, 我在使用过 ...

  2. datatable css not work

    样式不显示问题 无论是放内联样式文件还是直接放HTML文件都不显示 后来发现是因为datatable是放在后面初始化,它自带的样式覆盖了我们自定义的样式 所以要注意写code时,很多时候不是code不 ...

  3. 【two pointers 细节题】cf1041dD. Glider

    像这样细节老是打挂不行啊…… A plane is flying at a constant height of hh meters above the ground surface. Let's c ...

  4. destoon手机端mobileurl函数增加城市分类参数

    mobileurl函数在include/global.func.php 858行 共四个参数,moduleid-模型id,catid-分类id,itemid -文章id,page-页码 functio ...

  5. paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之fsm1各种style的timing/area比较

    整体说,一般还是用2段式,再加上output encodecd/default -X技巧.

  6. Thinkphp 5 调试执行的SQL语句

    在模型操作中 ,为了更好的查明错误,经常需要查看下最近使用的SQL语句,我们可以用getLastsql方法来输出上次执行的sql语句.例如: User::get(1); echo User::getL ...

  7. Spring Cloud构建微服务架构(三)消息总线

     注:此文不适合0基础学习者直接阅读,请先完整的将作者关于微服务的博文全部阅读一遍,如果还有疑问,可以再来阅读此文,地址:http://blog.csdn.net/sosfnima/article/d ...

  8. VSCode编译C/C++(一)MinGW安装配置指南

    为什么不用IDE? 更加专业.轻便.其过程对于理解计算机也有更多的帮助 安装过程: 首先进入http://mingw.org/  ,点击右侧最新发布,可以下载,然后安装 点击桌面MinGWInstal ...

  9. 15年多校第一场七题hdu5294

    要做这题,先要明白图的割,说白了就是 为了让原点无法到汇点要删几条边(之所以叫割,就是在图面上切一刀,减掉最小的边是原点和汇点成为两个集合),想到了割先放着一会用. 题中说只有沿最短路走才有可能追上, ...

  10. POJ 3281 网络流 拆点 Dining

    题意: 有F种食物和D种饮料,每头牛有各自喜欢的食物和饮料,而且每种食物或者饮料只能给一头牛. 求最多能有多少头牛能同时得到它喜欢的食物或者饮料. 分析: 把每个牛拆点,中间连一条容量为1的边,保证一 ...