您的位置:首页 > 其它

hdu 1174 爆头(点到空间直线距离)

2013-10-31 21:41 417 查看
看见这个标题就进去了,然后就水之。。。。

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>

#define mm(a,b) memset(a,b,sizeof(a))
using namespace std;

const int inf=0x7ffffff;
const double PI=acos(-1.0);
const double eps=1e-8;
const double e=2.7182818284590452354;

struct point
{
double x,y,z;
point() {}
point(double x,double y,double z): x(x),y(y),z(z) {}
};

point operator + (point a,point b){ return point(a.x+b.x,a.y+b.y,a.z+b.z);}
point operator - (point a,point b){ return point(a.x-b.x,a.y-b.y,a.z-b.z);}
point operator * (double a,point b) { return point(a*b.x,a*b.y,a*b.z);}

double dmult(point u,point v)
{
return u.x*v.x+u.y*v.y+u.z*v.z;
}
point xmult(point u,point v)
{
point 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;
}
int main()
{
int t;
point pc,te,dir,te_head,pc_head;
double h1,h2,h3,h4,r1,r2;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf%lf",&h1,&r1,&te.x,&te.y,&te.z);
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&h2,&r2,&pc.x,&pc.y,&pc.z,&dir.x,&dir.y,&dir.z);
h2=h2*0.9;
h4=h2-r2;
h3=h1-r1;
te_head=point(te.x,te.y,te.z+h3);
pc_head=point(pc.x,pc.y,pc.z+h4);
point n=te_head-pc_head;
point pp=xmult(n,dir);
double d=sqrt((pp.x*pp.x+pp.y*pp.y+pp.z*pp.z)/(dir.x*dir.x+dir.y*dir.y+dir.z*dir.z));
if(d<=r1 && dmult(n,dir)>0)
puts("YES");
else puts("NO");

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: