hdu 4617 Weapon【异面直线距离——基础三维几何】
链接:
Weapon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 224 Accepted Submission(s): 178
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.
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.
of two cylinders.
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
Lucky
2.32
Lucky
其实是盗版的KB大神的了。。。虽然他已经告诉了我是求异面直线的距离ORz kuangbin
题意:
算法:
思路:
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【异面直线距离——基础三维几何】的更多相关文章
- HDU 4617 Weapon (简单三维计算几何,异面直线距离)
Weapon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- hdu 4617 Weapon
http://acm.hdu.edu.cn/showproblem.php?pid=4617 三维几何简单题 多谢高尚博学长留下的模板 代码: #include <iostream> #i ...
- HDU 4617 Weapon(三维几何)
Problem Description Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a c ...
- HDU 4617 Weapon 三维计算几何
题意:给你一些无限长的圆柱,知道圆柱轴心直线(根据他给的三个点确定的平面求法向量即可)与半径,判断是否有圆柱相交.如果没有,输出柱面最小距离. 一共只有30个圆柱,直接暴力一下就行. 判相交/相切:空 ...
- hdu 4617 Weapon(叉积)
大一学弟表示刚学过高数,轻松无压力. 我等学长情何以堪= = 求空间无限延伸的两个圆柱体是否相交,其实就是叉积搞一搞 详细点就是求两圆心的向量在两直线(圆心所在的直线)叉积上的投影 代码略挫,看他的吧 ...
- hdu 5839(三维几何)
Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )
空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...
- hdu 1174:爆头(计算几何,三维叉积求点到线的距离)
爆头 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- 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 ...
随机推荐
- lodash camelCase 驼峰写法
_.camelCase([string='']) 转换字符串为 驼峰写法 _.camelCase('Foo Bar'); // => 'fooBar' _.camelCase('--foo-ba ...
- 非等高cell实战--实现微博页面
代码地址如下:http://www.demodashi.com/demo/11639.html 前言 学习过UITableView.AutoLayout以及MVC的相关知识,接下来通过一个微博页面实战 ...
- iOS开发-为我们的项目添加头文件prefix header
在XCode6新建项目时,不再自动创建头文件,因此我们需要手动添加. 点击我们的项目->Build Settings -> all -> 搜索“prefix” -> 修改pre ...
- requireJS目录
前言 对于像我这种requireJS初学者而言,requireJS最难理解的部分应该是它的路径问题.晚上随便折腾了一下,算是稍微理清了这个目录问题吧. requireJS学习网址:requireJS中 ...
- 基于Linux的智能家居的设计(5)
4 软件设计 软件设计部分主要包含uboot移植.内核编译.系统移植.设备驱动编程.应用程序编程(QT编程.mysql数据库编程.控制系统编程).各个模块的功能函数(部分是在windows以下的IA ...
- 基于Virtext6平台的GTX IP核基本设置说明
本工程基于以下条件使用: 板卡:DBF板v3.0 芯片型号:Virtex6 315T ISE版本:14.7 IP核版本: v6_gtxwizard : 1.12 一.IP核配置进行流程 第一页配置:线 ...
- 561. Array Partition I【easy】
561. Array Partition I[easy] Given an array of 2n integers, your task is to group these integers int ...
- random实现验证码功能
直接上代码: #-*- coding: utf-8 -*- #一个简单的验证码程序 import random #定义一个全局变量,初始值为空字符串 checkcode = '' for i in r ...
- Jetty锁定文件的问题
在windows系统上,jetty默认在运行时会锁定部署的文件.这对于需要在程序运行期间动态生成或改动某些文件就变得不能执行!对于这一点,Jetty的官网上专门有文章进行了解释:http://docs ...
- Git merge two repositories (ZZ)
转自 https://stackoverflow.com/questions/2428137/how-to-rebase-one-git-repository-onto-another-one If ...