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

一共只有30个圆柱,直接暴力一下就行。

判相交/相切:空间直线距离是否小于等于两圆柱半径和
若无相交,求最小:空间直线距离-两圆柱半径和

 #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; const double EPS = 1e-;
const int MAXN = ; struct Point3 //空间点
{
double x, y, z;
}; struct Line3 //空间直线
{
Point3 a, b;
}; struct plane3 //空间平面
{
Point3 a, b, c;
plane3(){}
plane3( Point3 a, Point3 b, Point3 c ):
a(a), b(b), c(c) { }
}; struct Cylinder
{
Point3 center; //圆柱轴线经过的一点
Point3 a, b; //与中心点在同一平面的两点
Line3 FaXian; //轴线
double R; //圆柱半径
}; Cylinder CC[MAXN]; Point3 Read_Point()
{
Point3 p;
scanf("%lf%lf%lf", &p.x, &p.y, &p.z );
return p;
} double dcmp( double a )
{
if ( fabs( a ) < EPS ) return ;
return a < ? - : ;
} //三维叉积
Point3 Cross3( Point3 u, Point3 v )
{
Point3 ret;
ret.x = u.y * v.z - v.y * u.z;
ret.y = u.z * v.x - u.x * v.z;
ret.z = u.x * v.y - u.y * v.x;
return ret;
} //三维点积
double Dot3( Point3 u, Point3 v )
{
return u.x * v.x + u.y * v.y + u.z * v.z;
} //矢量差
Point3 Subt( Point3 u, Point3 v )
{
Point3 ret;
ret.x = u.x - v.x;
ret.y = u.y - v.y;
ret.z = u.z - v.z;
return ret;
} //取平面法向量
Point3 NormalVector( plane3 s )
{
return Cross3( Subt( s.a, s.b ), Subt( s.b, s.c ) );
}
Point3 NormalVector( Point3 a, Point3 b, Point3 c )
{
return Cross3( Subt( a, b ), Subt( b, c ) );
} //两点距离
double TwoPointDistance( Point3 p1, Point3 p2 )
{
return sqrt( (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y) + (p1.z - p2.z)*(p1.z - p2.z) );
} //向量的模
double VectorLenth( Point3 p )
{
return sqrt( p.x*p.x + p.y*p.y + p.z*p.z );
} //空间直线距离
double LineToLine( Line3 u, Line3 v )
{
Point3 tmp = Cross3( Subt( u.a, u.b ), Subt( v.a, v.b ) );
return fabs( Dot3( Subt(u.a, v.a), tmp ) ) / VectorLenth(tmp);
} int N; int main()
{
int T;
scanf( "%d", &T );
while ( T-- )
{
scanf( "%d", &N );
for ( int i = ; i < N; ++i )
{
CC[i].center = Read_Point();
CC[i].a = Read_Point();
CC[i].b = Read_Point();
CC[i].R = VectorLenth( Subt( CC[i].a, CC[i].center ) );
CC[i].FaXian.a = CC[i].center;
CC[i].FaXian.b = Subt( CC[i].center, NormalVector( CC[i].center, CC[i].a, CC[i].b ) );
} bool ok = true;
double MinAns = 1e200;
for ( int i = ; ok && i < N; ++i )
for ( int j = i + ; ok && j < N; ++j )
{
double tmp = LineToLine( CC[i].FaXian, CC[j].FaXian );
if ( dcmp( tmp - ( CC[i].R + CC[j].R ) ) <= )
{
ok = false;
break;
}
MinAns = min( MinAns, tmp - ( CC[i].R + CC[j].R ) );
} if ( ok ) printf( "%.2f\n", MinAns );
else puts("Lucky");
}
return ;
}

HDU 4617 Weapon 三维计算几何的更多相关文章

  1. hdu 4617 Weapon【异面直线距离——基础三维几何】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others)     ...

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

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

  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

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

  5. hdu 4617 Weapon(叉积)

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

  6. HDU 5130 Signal Interference(计算几何 + 模板)

    HDU 5130 Signal Interference(计算几何 + 模板) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5130 Descripti ...

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

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

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

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

  9. HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...

随机推荐

  1. 以前用过Extjs技术的开发人员在学习Extjs4时需要注意的问题

            以前学习过Extjs的同学,在学习Extjs4的时候需要注意几个关键改变: 1.Extjs4的新的类系统. 2.Extjs4中MVC思路 3.Extjs4中的新的命名规范(结合新的MV ...

  2. BLUR

    ssao的blur遇到个麻烦 花了两三天时间...终于大概知道原因了. 在nvidia的ssao(http://developer.download.nvidia.com/SDK/10.5/direc ...

  3. Gitlab 7.12 发布 SAML支持及其他更多功能

    官方文章:https://about.gitlab.com/2015/06/22/gitlab-7-12-released/ CSDN翻译文章:http://geek.csdn.net/news/de ...

  4. js函数延迟执行

    function delay(value){ //全局变量保存当前值 window._myTempDalayValue = value; setTimeout(function(){ //延时之后与全 ...

  5. IE6 IE7 IE8(Q) 不支持 JSON 对象

    标准参考 JSON 是一种数据交换格式,RFC 4627 对 JSON 进行了详细描述. 根据 ECMA-262(ECMAScript)第 5 版中描述,JSON 是一个包含了函数 parse 和 s ...

  6. ubuntu修改ip、网关、dns等

    一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...

  7. 收集几个Web前端UI框架

    原文:http://www.isaced.com/post-200.html 关于Web前端UI库/框架,我觉得是非常方便的东西,对于我们这种业余的Web开发人员,有时候要写点前端代码的时候把UI框架 ...

  8. HDU3341 Lost's revenge(AC自动机&&dp)

    一看到ACGT就会想起AC自动机上的dp,这种奇怪的联想可能是源于某道叫DNA什么的题的. 题意,给你很多个长度不大于10的小串,小串最多有50个,然后有一个长度<40的串,然后让你将这个这个长 ...

  9. iOS16进制设置颜色

    UIColor+Hex.h // // UIColor+Hex.h // 16进制颜色类别 // // Created by apple on 15-4-3. // Copyright (c) 201 ...

  10. Message,MessageQueue,Looper,Handler详解

    Message,MessageQueue,Looper,Handler详解   一.几个关键概念 1.MessageQueue:是一种数据结构,见名知义,就是一个消息队列,存放消息的地方.每一个线程最 ...