Save Labman No.004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 624 Accepted Submission(s): 154
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.
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.
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.
1 0 1 0 1 1 0 0 0 1 1 1
0.500000 0.500000 1.000000 0.666667 0.666667 0.666667
详细公式见:
http://blog.sina.com.cn/s/blog_a401a1ea0101ij9z.html
然后直接使用公式就可以了。
/* ***********************************************
Author :kuangbin
Created Time :2013/9/15 星期日 13:01:15
File Name :2013杭州网络赛\1004.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
struct Point
{
double x,y,z;
Point(double _x = ,double _y = ,double _z = )
{
x = _x;
y = _y;
z = _z;
}
Point operator +(const Point &b)const
{
return Point(x + b.x, y + b.y,z + b.z);
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y,z - b.z);
}
Point operator /(double k)
{
return Point(x/k,y/k,z/k);
}
Point operator *(double k)
{
return Point(x*k,y*k,z*k);
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y + z*b.z;
}
Point operator ^(const Point &b)const
{
return Point(y*b.z - z *b.y,z*b.x - x*b.z, x*b.y - y * b.x);
}
void input()
{
scanf("%lf%lf%lf",&x,&y,&z);
}
void output()
{
printf("%.6lf %.6lf %.6lf",x,y,z);
}
};
double dis(Point a,Point b)
{
return sqrt((a.x - b.x) * (a.x- b.x) + (a.y - b.y) *(a.y - b.y) + (a.z - b.z)*(a.z - b.z));
}
double norm(Point a)
{
return sqrt(a.x *a.x + a.y *a.y + a.z * a.z);
}
Point A,B,C,D;
Point mid1,mid2;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
A.input();
B.input();
C.input();
D.input();
Point p1 = (B-A);
Point p2 = (D-C);
Point p = p1^p2; double dd = (p*(A-C))/norm(p);
dd = fabs(dd);
printf("%.6lf\n",dd); double t1 = ( (C-A)^p2 )*(p1^p2);
t1 /= norm(p1^p2)*norm(p1^p2);
double t2 = ( (C-A)^p1 )*(p1^p2);
t2 /= norm(p1^p2)*norm(p1^p2);
mid1 = A + (p1 * t1);
mid2 = C + (p2 * t2);
mid1.output();
printf(" ");
mid2.output();
printf("\n"); }
return ;
}