Weapon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 22    Accepted Submission(s): 18

Problem Description
  Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a circle. When it fires, rays form a cylinder that runs through the circle verticality in both side. If one cylinder of rays touch another, there will be an horrific explosion. Originally, all circles can rotate easily. But for some unknown reasons they can not rotate any more. If these weapon can also make an explosion, then Doctor D. is lucky that he can also test the power of the weapon. If not, he would try to make an explosion by other means. One way is to find a medium to connect two cylinder. But he need to know the minimum length of medium he will prepare. When the medium connect the surface of the two cylinder, it may make an explosion.
 
Input
  The first line contains an integer T, indicating the number of testcases. For each testcase, the first line contains one integer N(1 < N < 30), the number of weapons. Each of the next 3N lines  contains three float numbers. Every 3 lines represent one weapon. The first line represents the coordinates of center of the circle, and the second line and the third line represent two points in the circle which surrounds the center. It is supposed that these three points are not in one straight line. All float numbers are between -1000000 to 1000000.
 
Output
  For each testcase, if there are two cylinder can touch each other, then output 'Lucky', otherwise output then minimum distance of any two cylinders, rounded to two decimals, where distance of two cylinders is the minimum distance of any two point in the surface of two cylinders.
 
Sample Input
3
3
0 0 0
1 0 0
0 0 1
5 2 2
5 3 2
5 2 3
10 22 -2
11 22 -1
11 22 -3
3
0 0 0
1 0 1.5
1 0 -1.5
112 115 109
114 112 110
109 114 111
-110 -121 -130
-115 -129 -140
-104 -114 -119.801961
3
0 0 0
1 0 1.5
1 0 -1.5
112 115 109
114 112 110
109 114 111
-110 -121 -130
-120 -137 -150
-98 -107 -109.603922
 
Sample Output
Lucky
2.32
Lucky
 
Source
 
Recommend
zhuyuanchen520
 

题目意思自己理解吧。

相当于给了很多圆柱面,给的三个点是垂直界面上的点,一个是圆心,另外两个是圆上的两个点。

圆柱面无线长的。

求这些圆柱面上点的最小值,有相交输出Lucky

这样相等于求中间那条轴线的距离。

求异面直线距离。感觉轴平行的时候不好处理。。。

随便搞了下就可以AC了

数据比较水吧

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <math.h>
using namespace std;
const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point3D
{
double x,y,z;
Point3D(double _x = ,double _y = ,double _z = )
{
x = _x;
y = _y;
z = _z;
}
Point3D operator -(const Point3D &b)const
{
return Point3D(x-b.x,y-b.y,z-b.z);
}
Point3D operator ^(const Point3D &b)const
{
return Point3D(y*b.z-z*b.y,z*b.x-x*b.z,x*b.y-y*b.x);
}
double operator *(const Point3D &b)const
{
return x*b.x+y*b.y+z*b.z;
}
void input()
{
scanf("%lf%lf%lf",&x,&y,&z);
}
};
double Norm(Point3D p)
{
return sqrt(p*p);
}
//计算两个异面直线的距离
//第一条直线过点a,方向向量为k1,第二条直线过点
double calc(Point3D a,Point3D k1,Point3D b,Point3D k2)
{
Point3D tmp = k1^k2;
return fabs(tmp*(a-b))/sqrt(tmp*tmp);
} struct Node
{
Point3D o,p1,p2;
void input()
{
o.input();
p1.input();
p2.input();
}
}node[]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i = ;i < n;i++)
node[i].input();
bool flag = false;
double Min = 1e20;
for(int i = ;i < n;i++)
for(int j = i+;j < n;j++)
{
if(flag)break;
double r1 = sqrt((node[i].p1-node[i].o)*(node[i].p1-node[i].o));
double r2 = sqrt((node[j].p1-node[j].o)*(node[j].p1-node[j].o));
Point3D k1 = (node[i].p1-node[i].o)^(node[i].p2-node[i].o);
Point3D k2 = (node[j].p1-node[j].o)^(node[j].p2-node[j].o);
if(sgn(Norm(k1^k2))==)
{
if(sgn( Norm( k1^(node[i].o-node[j].o)) ) == )//同轴
{
if(sgn(r1-r2) == )
{
flag = true;
break;
}
else continue;
}
else
{
double dd = (k1*(node[i].o-node[j].o))/Norm(k1);
double d = sqrt( Norm(node[i].o-node[j].o)*Norm(node[i].o-node[j].o) - dd*dd );
if(d > fabs(r1-r2) &&d < fabs(r1+r2))
{
flag = true;
break;
}
Min = min(Min,d-r1-r2);
}
continue;
}
double d = calc(node[i].o,k1,node[j].o,k2);
if(d < r1 + r2 -eps)
{
flag = true;
break;
}
Min = min(Min,d-r1-r2);
}
if(flag || sgn(Min)<=)printf("Lucky\n");
else printf("%.2lf\n",Min);
}
return ;
}

HDU 4617 Weapon (简单三维计算几何,异面直线距离)的更多相关文章

  1. HDU 4617 Weapon(三维几何)

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

  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

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

  5. HDU 6373.Pinball -简单的计算几何+物理受力分析 (2018 Multi-University Training Contest 6 1012)

    6373.Pinball 物理受力分析题目. 画的有点丑,通过受力分析,先求出θ角,为arctan(b/a),就是atan(b/a),然后将重力加速度分解为垂直斜面的和平行斜面的,垂直斜面的记为a1, ...

  6. hdu 4617 Weapon(叉积)

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

  7. HDU 5234 Happy birthday --- 三维01背包

    HDU 5234 题目大意:给定n,m,k,以及n*m(n行m列)个数,k为背包容量,从(1,1)开始只能往下走或往右走,求到达(m,n)时能获得的最大价值 解题思路:dp[i][j][k]表示在位置 ...

  8. HDU 2085 核反应堆 --- 简单递推

    HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...

  9. Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】

    Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...

随机推荐

  1. CSS控制超链接

    一.伪类 CSS控制元素的某种状态---偽类(用于向某些选择器添加特殊的效果)    偽类的语法:元素标签 偽类名称{属性:属性值;} 二.超链接        a:link:未访问的链接       ...

  2. asp.net下通过泛解析和伪静态实现二级域名的实现方法

    在net中微软已经为我们留下了接口,让我们为所欲为了. 首先我们可以通过一张图大概了解下.net的生命周期. 从 上图可以看出来,针对每个不同用户的请求,服务器都会创建一个新的HttpContext实 ...

  3. mysql大数据导出导入

    1)导出 select * from users into outfile '/tmp/users.txt';或 select * from users where sex=1 into outfil ...

  4. hadoop DataNode实现分析

    在前面说hadoop整体实现的时候, 说过DataNode的需要完成的首要任务是K-V存储.                                            第二个功能是 完成和 ...

  5. POJ 1422 Air Raid (最小路径覆盖)

    题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...

  6. Wireshark基本介绍和学习TCP三次握手(转)

    http://www.cnblogs.com/TankXiao/archive/2012/10/10/2711777.html 之前写过一篇博客:用 Fiddler 来调试HTTP,HTTPS. 这篇 ...

  7. typedef 深入剖析

    typedef是一个我们常常会用到的关键字,而这个关键字有许多陷阱或者说许多不为我们深入理解的地方.很多书上都是很简单地一笔代过,并没有真正地让我们理解这个关键字.本文对其进行详细地说明.综合网络上找 ...

  8. Spring aop 实现异常拦截

    使用aop异常挂载功能可以统一处理方法抛出的异常,减少很多重复代码,实现如下: 1.实现ThrowAdvice public class ExceptionHandler implements Thr ...

  9. 深入浅出ghostbuster剖析NodeJS与PhantomJS的通讯机制

    深入浅出ghostbuster剖析NodeJS与PhantomJS的通讯机制 蔡建良 2013-11-14 一. 让我们开始吧 通过命令行来执行 1) 进行命令窗口: cmd 2) 进入resourc ...

  10. PHP中超全局变量$GLOBALS和global的区别

    一.超全局变量$GLOBALS PHP超全局变量有很多,如下的都属于超全局变量(Superglobal): $GLOBALS,$_SERVER,$_GET,$_POST,$_FILES,$_COOKI ...