题目多读几次就明白了。主要是求异面直线的距离,然后用距离和两圆半径之和作比较。

空间直线的距离d=|AB*n| / |n| (AB表示异面直线任意2点的连线,n表示法向量,法向量为两条异面直线方向向量的叉积,|n|表示模。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std;
const int MAXN=50;
const double eps=1e-8;
struct point {
double x,y,z;
};
struct line {
point a,b;
double r;
};
int n;
point tmp[3]; line le[MAXN];
point vectical; point operator - (const point &a, const point &b){ //减法
point t;
t.x=a.x-b.x; t.y=a.y-b.y; t.z=a.z-b.z;
return t;
}
point operator ^ (const point &u, const point &v){ //叉乘
point t;
t.x=u.y*v.z-v.y*u.z; t.y=u.z*v.x-u.x*v.z; t.z=u.x*v.y-u.y*v.x;
return t;
} point operator + (const point &a, const point &b){
point t;
t.x=a.x+b.x; t.y=a.y+b.y; t.z=a.z+b.z;
return t;
} double operator *(const point &a, const point &b){
return a.x*b.x+a.y*b.y+a.z*b.z;
} double dist(point &a, point &b){
double tx=a.x-b.x; double ty=a.y-b.y; double tz=a.z-b.z;
return sqrt(tx*tx+ty*ty+tz*tz);
} double len (point &t){
return sqrt(t.x*t.x+t.y*t.y+t.z*t.z);
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=0;i<n;i++){
for(int j=0;j<3;j++)
scanf("%lf%lf%lf",&tmp[j].x,&tmp[j].y,&tmp[j].z);
le[i].a=tmp[0];
vectical=(tmp[1]-tmp[0])^(tmp[2]-tmp[0]);
le[i].b=le[i].a+vectical;
le[i].r=dist(tmp[1],tmp[0]);
}
bool flag=false;
double ans=1e10;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i!=j){
vectical=(le[i].a-le[i].b)^(le[j].a-le[j].b);
point tt=le[i].a-le[j].a;
double dd=fabs((tt*vectical))/len(vectical);
if(dd<=le[i].r+le[j].r){
flag=true;
break;
}
else ans=min(ans,dd-le[i].r-le[j].r);
}
}
if(flag)break;
}
if(flag) printf("Lucky\n");
else printf("%.2lf\n",ans);
}
return 0;
}

  

HDU 4617的更多相关文章

  1. hdu 4617 Weapon

    http://acm.hdu.edu.cn/showproblem.php?pid=4617 三维几何简单题 多谢高尚博学长留下的模板 代码: #include <iostream> #i ...

  2. hdu 4617 Weapon【异面直线距离——基础三维几何】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others)     ...

  3. HDU 4617 Weapon 三维计算几何

    题意:给你一些无限长的圆柱,知道圆柱轴心直线(根据他给的三个点确定的平面求法向量即可)与半径,判断是否有圆柱相交.如果没有,输出柱面最小距离. 一共只有30个圆柱,直接暴力一下就行. 判相交/相切:空 ...

  4. HDU 4617 Weapon (简单三维计算几何,异面直线距离)

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

  5. hdu 4617 Weapon(叉积)

    大一学弟表示刚学过高数,轻松无压力. 我等学长情何以堪= = 求空间无限延伸的两个圆柱体是否相交,其实就是叉积搞一搞 详细点就是求两圆心的向量在两直线(圆心所在的直线)叉积上的投影 代码略挫,看他的吧 ...

  6. HDU 4617 Weapon(三维几何)

    Problem Description Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a c ...

  7. 【 2013 Multi-University Training Contest 2 】

    HDU 4611 Balls Rearrangement 令lcm=LCM(a,b),gcd=GCD(a,b).cal(n,a,b)表示sum(abs(i%a-i%b)),0<=i<n. ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. bzoj 3598 [ Scoi 2014 ] 方伯伯的商场之旅 ——数位DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3598 数位DP...东看西看:http://www.cnblogs.com/Artanis/ ...

  2. iOS社会化分享(干货)

    一.苹果原生集成的社会化分享 1.哪些平台 (1)Twitter (2)FaceBook (3)Flickr (4)Vimeo (5)新浪微博  :iOS6 (6)腾讯微博 : iOS7 2.框架 : ...

  3. 有关于dict(字典)的特性与操作方法

    有关于dict(字典)的特性与操作方法 1.字典的特性 语法: dic = {key1 : value1,key2 : value2,key3 : value3............} 注:字典中k ...

  4. css3 文本模型

    我前期是一名前端开发者,经常会遇到关于文本模型的问题,很多地方我们会经常遇到这种问题.例如栏目的标题,在设计师给我们图的时候并不会考虑到标题的长度,所以我们自己开发的过程中自己注意这一点. 首先和大家 ...

  5. go之for循环

    一.基于计数器的迭代 格式 for 初始化语句; 条件语句; 修饰语句{} 实例 package main import "fmt" func main(){ for i:=0;i ...

  6. android切换卡顿解决方法

    如果想要让应用用户流畅的滑动体验的话,那么就必须对activity和fragment的生命周期有一个完整的概念以及在何种情况下会触发哪些事件. 在自己目前做的项目中,就遇到了这样的问题,那么就把自己的 ...

  7. js实现“级联菜单”

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. macOS下登录store或者xcode等应用时提示【this action could not be completed】

    sudo mkdir -p /Users/Shared sudo chown root:wheel /Users/Shared sudo chmod -R 1777 /Users/Shared === ...

  9. 【sqli-labs】 less26a GET- Blind based -All you SPACES and COMMENTS belong to us -String-single quotes-Parenthesis(GET型基于盲注的去除了空格和注释的单引号括号注入)

    这个和less26差不多,空格还是用%a0代替,26过了这个也就简单了 ;%00 可以代替注释,尝试一下 order by 3 http://192.168.136.128/sqli-labs-mas ...

  10. webpack学习(二)

    时下很火的react项目多用到webpack+ES6,本文只实践webpack的打包功能,不涉及react. 1.新建项目 新建的项目,命令模式下切换到项目根路径,用npm init命令生成packa ...