编程介的小学生 2017-11-17 06:32 采纳率: 20.5%
浏览 483
已结题

Save Labman No.004

Problem Description
Due to the preeminent research conducted by Dr. Kyouma, human beings have a breakthrough in the understanding of time and universe. According to the research, the universe in common sense is not the only one. Multi World Line is running simultaneously. In simplicity, let us use a straight line in three-dimensional coordinate system to indicate a single World Line.

During the research in World Line Alpha, the assistant of Dr. Kyouma, also the Labman No.004, Christina dies. Dr. Kyouma wants to save his assistant. Thus, he has to build a Time Tunnel to jump from World Line Alpha to World Line Beta in which Christina can be saved. More specifically, a Time Tunnel is a line connecting World Line Alpha and World Line Beta. In order to minimizing the risks, Dr. Kyouma wants you, Labman No.003 to build a Time Tunnel with shortest length.

Input
The first line contains an integer T, indicating the number of test cases.

Each case contains only one line with 12 float numbers (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4), correspondingly indicating two points in World Line Alpha and World Line Beta. Note that a World Line is a three-dimensional line with infinite length.

Data satisfy T <= 10000, |x, y, z| <= 10,000.

Output
For each test case, please print two lines.

The first line contains one float number, indicating the length of best Time Tunnel.

The second line contains 6 float numbers (xa, ya, za), (xb, yb, zb), seperated by blank, correspondingly indicating the endpoints of the best Time Tunnel in World Line Alpha and World Line Beta.

All the output float number should be round to 6 digits after decimal point. Test cases guarantee the uniqueness of the best Time Tunnel.

Sample Input
1
1 0 1 0 1 1 0 0 0 1 1 1

Sample Output
0.408248
0.500000 0.500000 1.000000 0.666667 0.666667 0.666667

  • 写回答

2条回答 默认 最新

  • HHi3s 2018-08-03 21:41
    关注
     #include<cstdio>
    #include<cmath>
    inline double fun(double a, double b, double c, double d){
        return a*d - b*c;
    }
    
    #define squ(x) ((x)*(x))
    
    struct Poi
    {
        double x,y,z;
        Poi(double X = 0, double Y = 0, double Z = 0){
            x = X; y = Y; z = Z;
        }
        void input(){
            scanf("%lf%lf%lf",&x,&y,&z);
        }
        Poi operator + (const Poi & rhs){
            return Poi(x+rhs.x,y+rhs.y,z+rhs.z);
        }
        Poi operator - (Poi & rhs){
            return Poi(x-rhs.x,y-rhs.y,z-rhs.z);
        }
        Poi operator ^(Poi & rhs){
            return Poi(fun(y,z,rhs.y,rhs.z),-fun(x,z,rhs.x,rhs.z),fun(x,y,rhs.x,rhs.y));
        }
        Poi operator *(double t){
            return Poi(x*t,y*t,z*t);
        }
        double operator *(const Poi & rhs){
            return x*rhs.x+y*rhs.y+z*rhs.z;
        }
    };
    typedef Poi Vector;
    
    double Dot(const Vector & a,const Poi& b) {
         return a.x*b.x+a.y*b.y+a.z*b.z;
    }
    
    Poi LinePlaneIns(Poi &p1,Poi &p2,Poi &p0,Vector &n){
        Vector v = p2 - p1;
        double Ratio = (Dot(n,p0-p1))/(Dot(n,v));//保证相交
        return p1+v*Ratio;
    }
    double Length(const Vector &x){
        return sqrt(squ(x.x)+squ(x.y)+squ(x.z));
    }
    
    int main()
    {
       // freopen("in.txt","r",stdin);
        int T;
        scanf("%d",&T);
        while(T--){
            Poi p1,p2,p3,p4;
            p1.input();
            p2.input();
            p3.input();
            p4.input();
            Vector alpha = p2 - p1;
            Vector beta = p4 - p3;
            Vector gamma = alpha^beta;
            double distance = fabs(Dot(gamma,(p1-p3))/Length(gamma));
            Vector n1 = alpha^gamma;
            Vector n2 = beta^gamma;
            Poi ins1 = LinePlaneIns(p1,p2,p3,n2);
            Poi ins2 = LinePlaneIns(p3,p4,p1,n1);
            printf("%.6lf\n%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",distance,ins1.x,ins1.y,ins1.z,ins2.x,ins2.y,ins2.z);
        }
        return 0;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog