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 ...
随机推荐
- SC || Chapter 8
栈:方法调用和局部变量的存储位置,保存基本类型 堆:在一块内存里分为多个小块,每块包含 一个对象,或者未被占用
- Bootstrap 提示工具(Tooltip)插件方法的用法
方法 下面是一些提示工具(Tooltip)插件中有用的方法: 方法 描述 实例 Options: .tooltip(options) 向元素集合附加提示工具句柄. $().tooltip(option ...
- shell 练习题 - 第三周
1.编写脚本/root/bin/backup.sh,可实现每日将/etc/目录备份到 /root/etcYYYY-mm-dd中 #!/bin/bash echo "start backup& ...
- C#基础-字符串
字符串比较,strA.CompareTo(strB) A大于B 正数 A小于B 负数 A等于B 0 string strA = "ab"; string strB = " ...
- How to Install Zabbix Server on Centos6.7
Prerequisite Environment First you must use your Subscription Manager to enable SCL: [root@fileserve ...
- 在使用sql语句的一些注意事项(sql语句)
版权声明:本文为博主原创文章,未经博主允许不得转载. 原文地址: https://www.cnblogs.com/poterliu/p/4925483.html ①如果插入字段包含对应的表的所有字段, ...
- Java底层基础题
一.Java底层基础题 1.SpringMVC的原理以及返回数据如何渲染到jsp/html上? 答:Spring MVC的核心就是DispatcherServlet , 一个请求经过Dispatche ...
- jflash合并两个文件
有时候需要将两个代码块烧写进入单片机的flash,可以使用合并的方法将两个文件合并为一个文件进行烧写,也可以分两次烧写,但要注意不要擦写不相关的存储空间. 打开J-FLASH,新建一个工程,然后fil ...
- sqli-labs less1 &&less3&&less4学习心得
0x01.less1 id=1/ id=1 and 1=1结果正常 id=1 and 1=2结果正常,不合理 id=1'提示:
- Python并发(一)
假设我们要从一个网站用Python程序下载5张图片,最传统的思路就是写个for循环挨个挨个下载,但是这样做有个缺点,就是除了第一张,每张图片都必须等待前一张图片下载完毕后,才可以开始下载.由于网络有很 ...