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

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
 

详细公式见:

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 ;
}

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

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

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

  2. 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 ...

  3. HDU 4741 Save Labman No.004 2013 ACM/ICPC 杭州网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4741 题意:给你两条异面直线,然你求着两条直线的最短距离,并求出这条中垂线与两直线的交点. 需要注意的是 ...

  4. hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]

    // Time 234 ms; Memory 244 K #include<iostream> #include<cstdio> #include<cmath> u ...

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

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

  6. 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 ...

  7. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. hdu 4741 Save Labman No.004异面直线间的距离既构成最小距离的两个端点

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

  9. 2013杭州网络赛D题HDU 4741(计算几何 解三元一次方程组)

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

随机推荐

  1. Angular 下的 directive (part 2)

    ngCloak ngCloak指令被使用在,阻止angular模板从浏览器加载的时候出现闪烁的时候.使用它可以避免闪烁问题的出现.   该指令可以应用于<body>元素,但首选使用多个ng ...

  2. HTML5 移动开发 (HTML5标签和属性)

       第一阶    1.如何使用HTML5中的新标签及属性    2.HTML5中的其它变化    3.HTML5的移动支持    4.使用HTML5开发移动WEB引用的理由 第二阶    HTML5 ...

  3. HDU 1251 统计难题 字符匹配

    题目描述:先说明此题只有一个测试实例,然后输入一系列的单词,以一个回车为结束符,然后输入一个字符串,要你查找以这个字符串为前缀的单词的个数,处理到文件结束. 解题报告:一开始看到这题,竟然直接用暴力去 ...

  4. HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题

    题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...

  5. C++ 修饰符类型

    C++ 修饰符类型 C++ 允许在 char.int 和 double 数据类型前放置修饰符.修饰符用于改变基本类型的含义,所以它更能满足各种情境的需求. 下面列出了数据类型修饰符: signed u ...

  6. 在xampp与phpstorm环境下安装xdebug[转]

    XDebug是什么 很多PHP程序员调试使用echo.print_r().var_dump().printf()等,虽然对于有较丰富开发经验的程序员来说这些也已经足够了,他们往往可以在程序执行的过程中 ...

  7. java线程池的初探

    问题来源 发现学习很多技术都提到了线程池的技术,自己的线程池方面没有仔细研究过,现在看了点东西来这里总结下,最近发现写博客是一个很好的锻炼自己并且将学到的东西更加理解的一个方式. 问题探究 java的 ...

  8. hibernate的一对多和多对一关联

    一对一的关联就不写了,一般项目也用不到,如果可以一对一就直接合成一个表了,也不会出现一对一的关系. 本文主要研究一对多的关系. 1.一对多的关系研究: (1)RDB中关系表达:  多的一方创建外键指向 ...

  9. struct termios结构体详解

    一.数据成员 termios 函数族提供了一个常规的终端接口,用于控制非同步通信端口. 这个结构包含了至少下列成员:tcflag_t c_iflag;      /* 输入模式 */tcflag_t ...

  10. Zookeeper集群搭建以及python操作zk

    一.Zookeeper原理简介 ZooKeeper是一个开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等. Zookeeper设计目 ...