杭电ACM HDOJ 1174 爆头

#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
#define eps 1e-6
struct Node{
    double x,y,z;
}line[2];
double chaji(Node a,Node b){//叉积
    double x1=a.x;
    double y1=a.y;
    double z1=a.z;
    double x2=b.x;
    double y2=b.y;
    double z2=b.z;
    double x=y1*z2-z1*y2;
    double y=z1*x2-x1*z2;
    double z=x1*y2-y1*x2;
    return sqrt(x*x+y*y+z*z);
}
int main(){
    double h1,r1,x1,y1,z1;
    double h2,r2,x2,y2,z2,x3,y3,z3;
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%lf%lf%lf%lf%lf",&h1,&r1,&x1,&y1,&z1);//土匪
        scanf("%lf%lf%lf%lf%lf",&h2,&r2,&x2,&y2,&z2);//警察
        scanf("%lf%lf%lf",&x3,&y3,&z3);//方向
        line[0].x=x3;
        line[0].y=y3;
        line[0].z=z3;
        //两个头之间的线的方向
        line[1].x=x1-x2;
        line[1].y=y1-y2;
        line[1].z=z1+h1-r1-(h2*0.9+z2-r2);
        double d=chaji(line[0],line[1]);
        d/=sqrt(x3*x3+y3*y3+ z3*z3);
        if(d-r1<eps ) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

你可能感兴趣的:(杭电ACM HDOJ 1174 爆头)