HDU 4617 Weapon (简单三维计算几何,异面直线距离)
Weapon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 22 Accepted Submission(s): 18
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
2.32
Lucky
题目意思自己理解吧。
相当于给了很多圆柱面,给的三个点是垂直界面上的点,一个是圆心,另外两个是圆上的两个点。
圆柱面无线长的。
求这些圆柱面上点的最小值,有相交输出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 (简单三维计算几何,异面直线距离)的更多相关文章
- HDU 4617 Weapon(三维几何)
Problem Description Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a c ...
- hdu 4617 Weapon【异面直线距离——基础三维几何】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others) ...
- HDU 4617 Weapon 三维计算几何
题意:给你一些无限长的圆柱,知道圆柱轴心直线(根据他给的三个点确定的平面求法向量即可)与半径,判断是否有圆柱相交.如果没有,输出柱面最小距离. 一共只有30个圆柱,直接暴力一下就行. 判相交/相切:空 ...
- hdu 4617 Weapon
http://acm.hdu.edu.cn/showproblem.php?pid=4617 三维几何简单题 多谢高尚博学长留下的模板 代码: #include <iostream> #i ...
- HDU 6373.Pinball -简单的计算几何+物理受力分析 (2018 Multi-University Training Contest 6 1012)
6373.Pinball 物理受力分析题目. 画的有点丑,通过受力分析,先求出θ角,为arctan(b/a),就是atan(b/a),然后将重力加速度分解为垂直斜面的和平行斜面的,垂直斜面的记为a1, ...
- hdu 4617 Weapon(叉积)
大一学弟表示刚学过高数,轻松无压力. 我等学长情何以堪= = 求空间无限延伸的两个圆柱体是否相交,其实就是叉积搞一搞 详细点就是求两圆心的向量在两直线(圆心所在的直线)叉积上的投影 代码略挫,看他的吧 ...
- HDU 5234 Happy birthday --- 三维01背包
HDU 5234 题目大意:给定n,m,k,以及n*m(n行m列)个数,k为背包容量,从(1,1)开始只能往下走或往右走,求到达(m,n)时能获得的最大价值 解题思路:dp[i][j][k]表示在位置 ...
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
随机推荐
- 成功的GIT开发分支模型和策略
详细图文并茂以及git flow工具解释参考: http://danielkummer.github.io/git-flow-cheatsheet/index.zh_CN.html 原文地址:http ...
- http server 下载地址
windows 64为位:https://www.apachelounge.com/download/
- hibernate注解(转)
一.实体Bean 每个持久化POJO类都是一个实体Bean, 通过在类的定义中使用 @Entity 注解来进行声明. 声明实体Bean @Entity public class Flight impl ...
- IOS中设置cell的背景view和选中时的背景view 、设置cell最右边的指示器(比如箭头\文本标签)
一.Cell的设置 1.设置cell的背景view和选中时的背景view UIImageView *bg = [[UIImageView alloc] init]; bg.image = [UIIma ...
- iso中第三方框架SDWebImage的使用步骤
一.SDWebImage的使用 1.依赖的框架 * ImageIO.framework * MapKit.framework 2.UIImageView下载图片需要的头文件:UIImageView+W ...
- CI在CentOS中的部署与实践LNMP
1. 平台:lnmp CentOS6.4 (64bit) nginx1.2.4+php5.5.7配置过程中遇到的问题与处理方式: 1. 404错误: 原因:nginx中的配置请求路径的问题 2. 40 ...
- python练习程序(c100经典例4)
题目: 输入某年某月某日,判断这一天是这一年的第几天? def judge_run(year): a=year/4.0; b=year/100.0; c=year/400.0; if a==int(a ...
- 一起学CUDA(一)
前提是电脑的显卡支持CUDA,N卡一般是支持的,如果是A卡就没办法了.主要针对Windows环境,Linux和Mac也有相应的安装包.CUDA环境搭建:Step1:安装代码环境VS2010:Step2 ...
- Linux多线程下载工具Axel
一般情况,在 Linux 下我们习惯于用 wget 下载,但该工具的缺点就是无法进行多线程下载,所以往往有时候速度不够快.这里介绍的 Axel,是 Linux 下一款不错的 HTTP 或 FTP 高速 ...
- 实现输出h264直播流的rtmp服务器
RTMP(Real Time Messaging Protocol)是常见的流媒体协议,用来传输音视频数据,结合flash,广泛用于直播.点播.聊天等应用,以及pc.移动.嵌入式等平台,是做流媒体开发 ...