// Time 234 ms; Memory 244 K
#include<iostream>
#include<cstdio>
#include<cmath> using namespace std; typedef struct point
{
double x,y,z;
point(double xx=0,double yy=0,double zz=0):x(xx),y(yy),z(zz){}
}vector;
vector operator - (point a,point b)
{
return vector(a.x-b.x,a.y-b.y,a.z-b.z);
}
point operator + (point a,vector b)
{
return point(a.x+b.x,a.y+b.y,a.z+b.z);
}
vector operator * (vector a,double b)
{
return vector(a.x*b,a.y*b,a.z*b);
}
double dot(vector a,vector b)
{
return a.x*b.x+a.y*b.y+a.z*b.z;
}
double len(vector a)
{
return sqrt(dot(a,a));
}
vector cross(vector a,vector b)
{
return vector(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}
point inter(point a,point b,point c,point d,point e)
{
point fa=cross(b-a,c-a);
double t=dot(fa,a-d)/dot(fa,e-d);
return d+(e-d)*t;
}
vector resize(vector a,double b)
{
b/=len(a);
return a*b;
}
point ptol(point o,point a,point b)
{
point fa=cross(a-o,b-o);
point vec=cross(b-a,fa);
return o+resize(vec,len(fa)/len(b-a));
}
void gc(point a,point b,point c,point d,point &p1,point &p2)
{
point e=d+cross(a-b,c-d);
p1=inter(c,d,e,a,b);
p2=ptol(p1,c,d);
} int main()
{
int t;
point a,b,c,d,p,q;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.z,&b.x,&b.y,&b.z);
scanf("%lf%lf%lf%lf%lf%lf",&c.x,&c.y,&c.z,&d.x,&d.y,&d.z);
gc(a,b,c,d,p,q);
double l=len(p-q);
printf("%.6lf\n",l);
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",p.x,p.y,p.z,q.x,q.y,q.z);
}
return 0;
}

hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]的更多相关文章

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

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

  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 4741 Save Labman No.004异面直线间的距离既构成最小距离的两个端点

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

  4. hdu 4741 Save Labman No.004(2013杭州网络赛)

    http://blog.sina.com.cn/s/blog_a401a1ea0101ij9z.html 空间两直线上最近点对. 这个博客上给出了很好的点法式公式了...其实没有那么多的tricky. ...

  5. HDU 4741 Save Labman No.004(计算几何)

    题目链接 抄的模版...mark一下. #include <iostream> #include <cstring> #include <cstdio> #incl ...

  6. [HDU 4741]Save Labman No.004[计算几何][精度]

    题意: 求两条空间直线的距离,以及对应那条距离线段的两端点坐标. 思路: 有一个参数方程算最短距离的公式, 代入求即可. 但是这题卡精度... 用另外的公式(先算出a直线上到b最近的点p的坐标, 再算 ...

  7. hdu 4741 Save Labman No.004 (异面直线的距离)

    转载学习: #include <cstdio> #include <cstdlib> #include <cstring> #include <algorit ...

  8. HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )

    空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...

  9. HDU 4741 Save Labman No.004 (几何)

    题意:求空间两线的最短距离和最短线的交点 题解: 线性代数和空间几何,主要是用叉积,点积,几何. 知道两个方向向量s1,s2,求叉积可以得出他们的公共垂直向量,然后公共垂直向量gamma和两线上的点形 ...

随机推荐

  1. The number of positions

    Description The number of positions time limit per test: 0.5 second memory limit per test: 256 megab ...

  2. iphone:自定义UIAlertView

    由于项目中有这样一个需求:需要在保存是弹出框选择保存的地点.选择UIAlertView来实现,但是要在UIAlertView中增加UISwitch的控件,这就需要自定义一个继承UIAlertView的 ...

  3. ORACLE-Kill 杀死正在执行的Oracle存储过程和死锁语句

    ORACLE-Kill 杀死正在执行的Oracle存储过程和死锁语句 存储过程 1.找到正在执行的存储过程的 sid ,serial# select   b.sid,b.SERIAL#,a.OBJEC ...

  4. Oracle EBS-SQL (GL-1):从总帐追溯到接收

    SELECT je_header_id, je_line_num, trx_class_name, trx_type_name, trx_number_displayed, trx_date,comm ...

  5. android中onStartActivityForResult无返回值问题

    在activity间跳转传递参数,常见方法是通过onStartActivityForResult来做.不过今天使用 onStartActivityForResult的时候已经在上一个activity调 ...

  6. EditText无法失去焦点、失去焦点隐藏软键盘

    很奇怪,我在给EditText设置setOnFocusChangeListener()监听,但是始终未能成功,焦点一直存在,不知其原因,,代码如下: et_username.setOnFocusCha ...

  7. 排序-java

    今天座右铭----每天的学习会让我们不断地进步! 往往面试中都会让我们用一种排序方法做一道排序题,下面我就罗列出快速排序.冒泡排序.插入排序.选择排序的java代码! 1.快速排序 public cl ...

  8. nova的 microversion 实现

    之前想写nova的policy的实现, 但是发现网上,有人写的很不错了. 但是个人认为存在一些问题. ref: http://www.cnblogs.com/shaohef/p/4527436.htm ...

  9. 经常使用的DB2命令(2)

    catalog数据库: catalog indirect: db2 catalog database on /db2sys[dir_name] catalog remote:    db2 catal ...

  10. 采用proguard困惑android代码

    当前是有些工具比方apktool,dextojar等是能够对我们android安装包进行反编译.获得源代码的.为了降低被别人破解,导致源代码泄露,程序被别人盗代替码,等等.我们须要对代码进行混淆.an ...