Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 624 Accepted Submission(s): 154
详细公式见:
http://blog.sina.com.cn/s/blog_a401a1ea0101ij9z.html
然后直接使用公式就可以了。
1 /* *********************************************** 2 Author :kuangbin 3 Created Time :2013/9/15 星期日 13:01:15 4 File Name :2013杭州网络赛\1004.cpp 5 ************************************************ */ 6 7 #pragma comment(linker, "/STACK:1024000000,1024000000") 8 #include <stdio.h> 9 #include <string.h> 10 #include <iostream> 11 #include <algorithm> 12 #include <vector> 13 #include <queue> 14 #include <set> 15 #include <map> 16 #include <string> 17 #include <math.h> 18 #include <stdlib.h> 19 #include <time.h> 20 using namespace std; 21 struct Point 22 { 23 double x,y,z; 24 Point(double _x = 0,double _y = 0,double _z = 0) 25 { 26 x = _x; 27 y = _y; 28 z = _z; 29 } 30 Point operator +(const Point &b)const 31 { 32 return Point(x + b.x, y + b.y,z + b.z); 33 } 34 Point operator -(const Point &b)const 35 { 36 return Point(x - b.x, y - b.y,z - b.z); 37 } 38 Point operator /(double k) 39 { 40 return Point(x/k,y/k,z/k); 41 } 42 Point operator *(double k) 43 { 44 return Point(x*k,y*k,z*k); 45 } 46 double operator *(const Point &b)const 47 { 48 return x*b.x + y*b.y + z*b.z; 49 } 50 Point operator ^(const Point &b)const 51 { 52 return Point(y*b.z - z *b.y,z*b.x - x*b.z, x*b.y - y * b.x); 53 } 54 void input() 55 { 56 scanf("%lf%lf%lf",&x,&y,&z); 57 } 58 void output() 59 { 60 printf("%.6lf %.6lf %.6lf",x,y,z); 61 } 62 }; 63 double dis(Point a,Point b) 64 { 65 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)); 66 } 67 double norm(Point a) 68 { 69 return sqrt(a.x *a.x + a.y *a.y + a.z * a.z); 70 } 71 Point A,B,C,D; 72 Point mid1,mid2; 73 int main() 74 { 75 //freopen("in.txt","r",stdin); 76 //freopen("out.txt","w",stdout); 77 int T; 78 scanf("%d",&T); 79 while(T--) 80 { 81 A.input(); 82 B.input(); 83 C.input(); 84 D.input(); 85 Point p1 = (B-A); 86 Point p2 = (D-C); 87 Point p = p1^p2; 88 89 double dd = (p*(A-C))/norm(p); 90 dd = fabs(dd); 91 printf("%.6lf\n",dd); 92 93 double t1 = ( (C-A)^p2 )*(p1^p2); 94 t1 /= norm(p1^p2)*norm(p1^p2); 95 double t2 = ( (C-A)^p1 )*(p1^p2); 96 t2 /= norm(p1^p2)*norm(p1^p2); 97 mid1 = A + (p1 * t1); 98 mid2 = C + (p2 * t2); 99 mid1.output(); 100 printf(" "); 101 mid2.output(); 102 printf("\n"); 103 104 } 105 return 0; 106 }