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

一共只有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. Careercup - Google面试题 - 4847954317803520

    2014-05-08 21:33 题目链接 原题: largest number that an int variable can fit given a memory of certain size ...

  2. 【转】EXT VTYPE自定义举例

    原文地址:http://www.blogjava.net/xiaohuzi2008/archive/2012/12/08/392676.html 近日来对Ext特别感兴趣,也许是它那种OO的设计思想吸 ...

  3. Codeforces Round #284 (Div. 2)

    题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...

  4. 【BZOJ】【1011】【HNOI2008】遥远的行星

    神奇的思路题QAQ 玛雅看到这题我就醉了,什么玩意……5%的误差?果断膜拜@ydc神犇的题解: 就是因为不清楚如何应用那个答案误差不超过5%啦. 从没见过这么诡异的题一下就懵了,问到了方法之后都还半信 ...

  5. Leetcode#97 Interleaving String

    原题地址 转化为二维地图游走问题. 比如s1="abab",s2="aab",s3="aabaabb",则有如下地图,其中"^&q ...

  6. 【bzoj1003】[ZJOI2006]物流运输

    1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6331  Solved: 2610[Submit][Stat ...

  7. fiddler 新发现

    就一句话,记录一下 urlreplace baidu.com taobao.com //Fiddler2\Scripts\SampleRules.js 这里发现的 case "urlrepl ...

  8. 驱动笔记 - IO端口和IO内存

    访问IO端口 (#include <asm/io.h>) 设备资源struct resource{ resource_size_t start; //资源起始物理地址 resource_s ...

  9. java正则表达式解析短信模板

    /** * */ package testJava.java; import java.util.HashMap; import java.util.Map; import java.util.Sca ...

  10. java输出流实现文件下载

    //导出Excel try { HSSFWorkbook wb = carService.export(list); //调用service方法~! response.setContentType(& ...