// 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. Android studio听云接入另外一种方式

    1.在build.gradle中集成听云. buildscript { repositories { mavenCentral() } dependencies { classpath fileTre ...

  2. 页面类跳转Demo

    package baidumapsdk.demo; import android.app.Activity; import android.content.BroadcastReceiver; imp ...

  3. 关于arguments.callee的用途

    arguments为js函数中两个隐藏属性中的一个(另一个为this) arguments表示所有传入的参数,为类数组(array-like)类型,arguments.length表示传入参数的长度, ...

  4. 线程间使用socket通信的计算器

    该程序是处理平时的算数运算,程序也没有什么特别之处,只是将所有运算分开运算,每个函数(线程)处理不同的运算符号里面的运算,然后将所有结果都汇总到main函数中进行最后汇总(相加减)运算,每个函数内都处 ...

  5. Eclipse下如何打开ftl文件

    ftl文件是freemarker模板文件,用freemarker时,常用该文件模板:但是该文件在eclipse编辑时,黑白底的,没有任何提示,下面介绍如何用JSP编辑器打开该文件. 工具/原料   e ...

  6. sql查询数据库表中重复记录方法

    1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 代码如下: select * from people where peopleId in (select peopleId ...

  7. delphi 7中使用idhttp抓取网页 解决假死现象

    在delphi 7中使用idhttp抓取网页,造成窗口无反应的假死状态.通过搜索获得两种方法. 1.写在线程中,但是调用比较麻烦 2.使用delphi 提供的idantifreeze(必须安装indy ...

  8. nginx 通过rsyslog发日志 rsyslog服务器挂掉 日志丢失问题

    nginx 配置: user nginx; worker_processes 1; syslog local5 nginx-zjzc01; rsyslog 服务器收到的消息: -rw-r--r-- 1 ...

  9. VC中实现带有背景位图的树型控件

    当前许多应用程序都在使用树型控件时为其添加了背景位图,增强的控件的魅力,然而对于Visual C++编程爱好者来说,使用Visual C++MFC提供的树型控件(CTreeCtrl)本身就是一个难点, ...

  10. iOS 退出应用程序

    退出应用程序,方法很简单,只是动画效果没有那么好. - (void)exitApplication { AppDelegate *app = [UIApplication sharedApplicat ...