2013 ACM/ICPC Asia Regional Hangzhou Online–1004

hdoj4741 Save Labman No.004

#include<stdio.h>
#include<string.h>
#include<math.h>
typedef struct Point{
    double x,y,z;
}Point;
Point operator +(const Point &a,const Point &b)
{
    Point res;
    res.x=a.x+b.x;res.y=a.y+b.y;res.z=a.z+b.z;
    return res;
}
Point operator *(const Point &a,const double t)
{
    Point res;
    res.x=a.x*t;res.y=a.y*t;res.z=a.z*t;
    return res;
}
Point operator -(const Point &a,const Point &b)
{
    Point res;
    res.x=a.x-b.x;res.y=a.y-b.y;res.z=a.z-b.z;
    return res;
}
double operator *(const Point &a,const Point &b)
{
    return a.x*b.x+a.y*b.y+a.z*b.z;
}
Point operator /(const Point &a,const Point &b)
{
    Point res;
    res.x=a.y*b.z-b.y*a.z;
    res.y=b.x*a.z-a.x*b.z;
    res.z=a.x*b.y-a.y*b.x;
    return res;
}
double daxiao(Point a)
{
    return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
}
Point p1,p2,p3,p4;
int main()
{
    int i,j,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p1.z,&p2.x,&p2.y,&p2.z,&p3.x,&p3.y,&p3.z,&p4.x,&p4.y,&p4.z);
        Point n1=p2-p1;
        Point n2=p4-p3;
        Point p=n1/n2;
        Point q=p3-p2;
        double d=fabs((p*q)/daxiao(p));
        double tmp=daxiao(n1/n2);
        Point delta=p3-p1;
        double t1=((delta/n2)*(n1/n2))/(tmp*tmp);
        double t2=((delta/n1)*(n1/n2))/(tmp*tmp);
        Point ans1=p1+(n1*t1);
        Point ans2=p3+(n2*t2);
        printf("%.6f\n",d);
        printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",ans1.x,ans1.y,ans1.z,ans2.x,ans2.y,ans2.z);
    }
    return 0;
}