Save Labman No.004

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 979    Accepted Submission(s): 306

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
 
Source
 
Recommend
liuyiding
 
 
题目大意:当时看见这个题目蛮激动的,因为求异面直线的最短距离前不久还写过博客,不过那样只能求最短距离。当时被迫与无奈。题目大意很简单,给你两条直线,问你最短距离是多少,并且求出最短距离的点,需要求得点是唯一的。

解题思路:当时自己想的就是先把两条直线求出来,然后分别在两条直线上找俩点p和q。这样未知数就有两个,然后再求公垂线,根据公垂线与pq共线xyz三维坐标即可列出三元一次方程组,未知数三个,方程有三个。只是算起来不是很顺手。详见AC代码。

题目地址:Save Labman No.004

AC代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std; int main()
{
int tes;
double x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4;
double a1,b1,c1,a2,b2,c2;
scanf("%d",&tes);
while(tes--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&z1,&x2,&y2,&z2,&x3,&y3,&z3,&x4,&y4,&z4);
a1=x2-x1,b1=y2-y1,c1=z2-z1; //第一条直线
a2=x4-x3,b2=y4-y3,c2=z4-z3; //第二条直线
double k1,k2;
double p1,p2,p3; //p点
double q1,q2,q3; //q点
double s1,s2,s3; //前两条直线的公垂线
s1=b1*c2-b2*c1;
s2=c1*a2-c2*a1;
s3=a1*b2-a2*b1;
//方程组转化为
//t1*k1+t2*k2=t3,m1*k1+m2*k2=m3;
double t1,t2,t3,m1,m2,m3;
t1=s2*a1-s1*b1,t2=s1*b2-s2*a2,t3=s1*(y1-y3)-s2*(x1-x3);
m1=s3*a1-s1*c1,m2=s1*c2-s3*a2,m3=s1*(z1-z3)-s3*(x1-x3);
k1=(t3*m2-m3*t2)/(t1*m2-m1*t2);
k2=(t3*m1-m3*t1)/(t2*m1-m2*t1); p1=k1*a1+x1,p2=k1*b1+y1,p3=k1*c1+z1,
q1=k2*a2+x3,q2=k2*b2+y3,q3=k2*c2+z3;
double dis=sqrt((p1-q1)*(p1-q1)+(p2-q2)*(p2-q2)+(p3-q3)*(p3-q3));
printf("%.6lf\n",dis);
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",p1,p2,p3,q1,q2,q3);
}
return 0;
} /*
23
0 0 0 0 0 1 1 0 0 0 1 0
*/
//234MS 248K

2013杭州网络赛D题HDU 4741(计算几何 解三元一次方程组)的更多相关文章

  1. 2013杭州网络赛C题HDU 4640(模拟)

    The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  2. HDU 4741 Save Labman No.004 (2013杭州网络赛1004题,求三维空间异面直线的距离及最近点)

    Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  5. HDU 4739 Zhuge Liang's Mines (2013杭州网络赛1002题)

    Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  7. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)

    Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

随机推荐

  1. 数据库课本SQL第三章答案

    3 .用 sQL 语句建立第二章习题 5 中的 4 个表. 答: 对于 S 表: S ( SNO , SNAME , STATUS , CITY ) ; 建 S 表: CREATE TABLE S ( ...

  2. Flink资料(4) -- 类型抽取和序列化

    类型抽取和序列化 本文翻译自Type Extraction and Serialization Flink处理类型的方式比较特殊,包括它自己的类型描述,一般类型抽取和类型序列化框架.该文档描述这些概念 ...

  3. python相似模块用例(一)

    一:threading VS Thread 众所周知,python是支持多线程的,而且是native的线程,其中threading是对Thread模块做了包装,可以更加方面的被使用,threading ...

  4. [C#]Windows文件分类器小程序

    我平时习惯把各种文件都下载在`下载`文件夹中,时间久了,文件多了,想要找个文件就不那么方便了.于是我就想自己写一个小程序来实现下载文件的自动整理.我想到的文件分类方式是按照文件扩展名分类:把各文件移动 ...

  5. ArcEngine 9.3 学习笔记(六):图层符号化(COlorRamp,MarkerSymbol,LineSymbol,FillSymbol,TextSymbol,3DChartSymbol,使用ServerStyle符号库,FeatureRender,RasterRender)

    第四章 图层符号化 AE9.3 提供了SymbologyControl控件,用于显示ARCGIS符号库中的符号. 组件库中的组件对象分为Color(颜色),Symbol(符号),Render(渲染)三 ...

  6. C++中输入输出流及文件流操作笔记

    1.流的控制 iomanip          在使用格式化I/O时应包含此头文件.    stdiostream   用于混合使用C和C + +的I/O机制时,例如想将C程序转变为C++程序 2.类 ...

  7. javascript数组去重算法-----5

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Effective Objective-C 读书笔记

    一本不错的书,给出了52条建议来优化程序的性能,对初学者有不错的指导作用,但是对高级阶段的程序员可能帮助不是很大.这里贴出部分笔记: 第2条: 使用#improt导入头文件会把头文件的内容全部暴露到目 ...

  9. Android 匿名共享内存C++接口分析

    在上一篇Android 匿名共享内存C接口分析中介绍了Android系统的匿名共享内存C语言访问接口,本文在前文的基础上继续介绍Android系统的匿名共享内存提供的C++访问接口.在C++层通过引入 ...

  10. 使用window.postMessage实现跨域通信

    JavaScript由于同源策略的限制,跨域通信一直是棘手的问题.当然解决方案也有很多: document.domain+iframe的设置,应用于主域相同而子域不同: 利用iframe和locati ...