链接:


Weapon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

Total Submission(s): 224    Accepted Submission(s): 178

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
 

其实是盗版的KB大神的了。。。虽然他已经告诉了我是求异面直线的距离ORz kuangbin

题意:


 博士发明了一种武器,武器的枪口是圆的,一旦点火,那么能量射线就会从圆的两端都出来
 【这样就形成了底面圆确定,长度不限的圆柱体】
一旦有两个这样的能量圆柱体相遇【个人认为是包含了相切或者一个圆柱体包含了一个圆柱体的情况也算的,不过数据中没有】
那么就会发生爆炸,这样博士就能检测武器的威力了。

                                                    
我认为只要不是第一种情况都应该可以输出  Lucky了


下面给出 T 组测试数据
每组测试数据包含了 N  个圆柱体
对于每一个圆柱体给出了它的底面圆的圆心坐标和底面圆圆周上的两个点

如果给出的圆所形成的圆柱体至少能有两个相遇,那么显然博士可以直接检测他们的威力,直接输出 Lucky

如果没有任何的圆柱体相遇,那么就求出所有的圆柱体中相邻最近的距离,也就是找最小的距离了。


算法:


异面直线距离 : 【百度百科

向量方法:先求两异面直线的公共法向量,再求两异面直线上两点的连结线段在公共法向量上的射影长。

思路:

把每一个圆面都与其它所有的圆面两两比较,看他们所形成的圆柱体是否有相交的

如何实现:求出圆柱体间的轴线间的距离与他们的半径比较就好了。

个人认为不用考虑轴线是否平行甚至共线的问题,应该是数据比较水了,怎么乱搞都过了Orz


code:

Accepted 4617 15MS 244K 3486 B C++ free斩
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std; const int maxn = 30+10; const double eps = 1e-10;
int dcmp(double x) //精度
{
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
} struct Point3D{
double x;
double y;
double z; Point3D() {}
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);
}
double operator *(const Point3D &b) const //点积
{
return 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);
} void input()
{
scanf("%lf%lf%lf", &x,&y,&z);
}
};
typedef Point3D Vector3D; struct Circle{
Point3D o, p1, p2; void input()
{
o.input();
p1.input();
p2.input();
}
}circle[maxn]; double Length3D(Point3D p) //向量长度
{
return sqrt(p*p);
} //两异面直线距离【两直线上的点的连线在其法向量上的投影】
double cal(Point3D p1, Vector3D k1, Point3D p2, Vector3D k2)
{
Point3D nV = k1^k2; //normalVector
return fabs(nV*(p1-p2)) / Length3D(nV);
} int main()
{
int T;
int n;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
circle[i].input();
bool flag = false;
double Min = 3000000; for(int i = 0; i < n && !flag; i++)
{
for(int j = i+1; j < n && !flag; j++)
{
Circle c1 = circle[i];
Circle c2 = circle[j]; double r1 = Length3D(c1.p1-c1.o); //圆半径
double r2 = Length3D(c2.p1-c2.o);
Vector3D k1 = (c1.p1-c1.o)^(c1.p2-c1.o); //轴线的方向
Vector3D k2 = (c2.p1-c2.o)^(c2.p2-c2.o); double d = cal(c1.o, k1, c2.o, k2); //两异面直线距离
if(d <= r1+r2) //两圆相交或相切甚至内含应该都可以【题目不严谨没有相切和内含的数据】
{
flag = true;
break;
}
Min = min(Min, d-r1-r2);
}
}
if(flag) printf("Lucky\n");
else if(dcmp(Min) <= 0) printf("Lucky\n");
else printf("%.2lf\n", Min);
}
return 0;
}

hdu 4617 Weapon【异面直线距离——基础三维几何】的更多相关文章

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

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

  2. hdu 4617 Weapon

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

  3. HDU 4617 Weapon(三维几何)

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

  4. HDU 4617 Weapon 三维计算几何

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

  5. hdu 4617 Weapon(叉积)

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

  6. hdu 5839(三维几何)

    Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  7. HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )

    空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...

  8. hdu 1174:爆头(计算几何,三维叉积求点到线的距离)

    爆头 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  9. HDU 5533Dancing Stars on Me 基础几何

    Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...

随机推荐

  1. [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.

    1.滑动时候警告[Intervention] Unable to preventDefault inside passive event listener due to target being tr ...

  2. java的IO操作:System类对IO的支持。

    目标: 1,掌握SYStem对IO的三种支持: system.out system.in system.err 2,掌握system.out及system.err的区别. 3,掌握输入,输出重定向. ...

  3. 你被美国监控了,美国监控丑闻——"棱镜项目"事件

    http://www.ittime.com.cn/index.php?m=content&c=index&a=show&catid=29&id=3795 “棱镜”项目所 ...

  4. SpringCloud系列九:脱离Eureka使用Ribbon

    1. 回顾 在前文的示例中,是将Ribbon与Eureka配合使用的.但是现实中可能不具备这样的条件,例如一些遗留的微服务,它们可能并没有注册到Eureka Server上, 甚至根本不是使用Spri ...

  5. gitlab 6 安装备忘录

    gitlab 6.2-stable;Ubuntu 13.10;ruby 2.0.0 推荐使用PostgreSQL,MySQL不同版本可能碰到兼容性问题(www.oschina.net/question ...

  6. Atitit.uml2 api 的编程代码实现设计uml开发 使用eclipse jar java 版本

    Atitit.uml2 api 的编程代码实现设计uml开发 使用eclipse jar java 版本 1. clipse提供了UML的底层Java包, 1 2. MDTUML2Getting St ...

  7. Atitit..状态机与词法分析  通用分词器 分词引擎的设计与实现 attilax总结

    Atitit..状态机与词法分析  通用分词器 分词引擎的设计与实现 attilax总结 1. 状态机 理论参考1 2. 词法分析理论1 3. 词法分析实例2 4. ---code fsm 状态机通用 ...

  8. UML类图详解_关联关系_多对一

    首先先来明确一个概念,即多重性.什么是多重性呢?多重性是指两个对象之间的链接数目,表示法是“下限...上限”,最小数据为零(0),最大数目为没有设限(*),如果仅标示一个数目级上下限相同. 实际在UM ...

  9. linux学习之缓存机制

    linux中的缓存机制 在Linux系统中,为了提高文件系统性能,内核利用一部分物理内存分配出缓冲区,用于缓存系统操作和数据文件,当内核收到读写的请求时,内核先去缓存区找是否有请求的数据,有就直接返回 ...

  10. Unity3D - LINEAR INTERPOLATION

    原文地址:http://unity3d.com/learn/tutorials/modules/beginner/scripting/linear-interpolation 水平有限,翻译粗略,欢迎 ...