hdu 4671 异面直线的距离
题目大意:空间中有许多无限长的棒子(圆柱体),求棒子间最小距离。
#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 异面直线的距离的更多相关文章
- HDU 4617Weapon(两条异面直线的距离)
Weapon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- hdu 4741 Save Labman No.004 (异面直线的距离)
转载学习: #include <cstdio> #include <cstdlib> #include <cstring> #include <algorit ...
- 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 ...
- Hdu 4312-Meeting point-2 切比雪夫距离,曼哈顿距离,前缀和
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4312 Meeting point-2 Time Limit: 2000/1000 MS (Java/Ot ...
- Hdu 4311-Meeting point-1 曼哈顿距离,前缀和
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4311 Meeting point-1 Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 4666 Hyperspace(曼哈顿距离)
题目链接 这是HDU第400个题. #include <cstdio> #include <cstring> #include <set> #include < ...
- hdu 4666 最大曼哈顿距离
思路:这题我是看了题目后,上百度搜了一下才知道还有求最大曼哈顿距离的方法.直接把代码copy过来,研读一下,知道了代码实现机制,自然就很容易想到用优先队列来维护每种状态下的xi,yi之和的最大值最小值 ...
- HDU - 3567 IDA* + 曼哈顿距离 + 康托 [kuangbin带你飞]专题二
这题难度颇大啊,TLE一天了,测试数据组数太多了.双向广度优先搜索不能得到字典序最小的,一直WA. 思路:利用IDA*算法,当前状态到达目标状态的可能最小步数就是曼哈顿距离,用于搜索中的剪枝.下次搜索 ...
- HDU 4671 Partition(定理题)
题目链接 这题,明显考察搜索能力...在中文版的维基百科中找到了公式. #include <cstdio> #include <cstring> #include <st ...
随机推荐
- PAT (Basic Level) Practise (中文)- 1018. 锤子剪刀布 (20)
http://www.patest.cn/contests/pat-b-practise/1018 大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统 ...
- Python Web 架构
1. Django(全能型)2. Tornado3. BottlePython+Bottle+Sina SAE快速构建网站http://www.cnblogs.com/Xjng/p/3511983.h ...
- cocos2dx 3.x for lua "异步加载"实现过程
在lua中,cocos2dx 建立的栈只能被一个线程(主线程)访问,如果在c++建立子线程,然后通过c++调用lua回调函数实现异步加载就会报错. 如果试图通过c++子线程直接实现加载资源,返回一个布 ...
- 创建自定义 Estimator
ref 本文档介绍了自定义 Estimator.具体而言,本文档介绍了如何创建自定义 Estimator 来模拟预创建的 Estimator DNNClassifier 在解决鸢尾花问题时的行为.要详 ...
- Bzoj 近期题目一句话题解
目录 Bzoj 近期题目题解 1000: A+B Problem (模拟) 1008: [HNOI2008]越狱 (容斥) 1012: [JSOI2008]最大数maxnumber (线段树) 103 ...
- 【数论分块】bzoj2956: 模积和
数论分块并不精通……第一次调了一个多小时才搞到60pts:因为不会处理i==j的情况,只能枚举了…… Description $\sum_{i=1}^{n}\sum_{j=1 \land i \not ...
- 标准C++(1)
一.引用 引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样. 引用的声明方法:类型标识符 &引用名=目标变量名: 例: int& num; 引用类似于起别名 注 ...
- 第一本C语言笔记(上)
1. 一般地源程序文件到可执行程序文件经过如下四步: 预处理 -- 头文件内容插入.宏替换.删注释(#include.#define) 编译 -- 把预处理过的源文件编程汇编文件 .c -> . ...
- DC 课程内容
- Python语言的简介
___________________________________________________________我是一条分割线__________________________________ ...