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. R语言的向量化编程思维

    1.计算缺失值比例 perNA<- mean(is.na(Data1)) 2.按值替换 #which返回值是符合条件的下标 NAIDX<- which(Data2<=3 | Data ...

  2. 51nod1627 瞬间移动

    打表可以看出来是组合数...妈呀为什么弄成n+m-4,n-1,m-3就错啊... //打表可以看出来是组合数...妈呀为什么弄成n+m-4,n-1,m-3就错啊... #include<cstd ...

  3. css新增UI样式

    1.圆角 border-radius <style> .box{width:200px;height:300px;border:1px solid #000;border-radius:1 ...

  4. POJ 2084 Game of Connections

    卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int ...

  5. Oracle buffer cache与相关的latch等待事件

    buffer cache与相关的latch等待事件 1.buffer cache 2.latch:cache buffers lru chain 3.latch:cache buffers chain ...

  6. 安装完eclipse,dbwear后,需要在他们解压文件.ini下加上你liux的jdk的安装路径,才能正常使用

    -vm/usr/java/jdk/jdk1.6.0_45/bin/java

  7. 【转】Mac OS X开机启动Path had bad permissions错误解决方案

    原文网址:http://www.07net01.com/2015/07/884646.html 最近在安装mongodb的时候遇到了上述提示,在国内各大网站寻找解决方案无果,于是果断查看国外的网站,终 ...

  8. 【转】安装Django

    原文网址:http://www.crifan.com/record_install_django/ 1.参考Quick install guide,最终找到下载的地址: http://bitnami. ...

  9. C#中的枚举类型(enum type)

    ylbtech 原文 C#中的枚举类型(enum type) 概念 枚举类型(enum type)是具有一组命名常量的独特的值类型.在以下示例中: enum Color { Red, Green, B ...

  10. 自定义View--一个简单地圆形Progress效果

    先看效果图吧 我们要实现一个自定义的再一个圆形中绘制一个弧形的自定义View,思路是这样的: 先要创建一个类ProgressView,继承自View类,然后重写其中的两个构造方法,一个是一个参数的,一 ...