传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4741

题意:给你两条异面直线,然你求着两条直线的最短距离,并求出这条中垂线与两直线的交点。

需要注意的是,不知道为什么用double就WA了,但是改为long double就AC了。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=1100;
const int INF=0x3f3f3f3f;
const long double PI=acos(-1.0);
const long double eps=1e-7; bool zero(long double x)
{
if(fabs(x)<eps)
return true;
return false;
} struct point3D
{
long double x,y,z;
point3D(){};
point3D(long double a,long double b,long double c):x(a),y(b),z(c){}
void input()
{
double a,b,c;
scanf("%lf%lf%lf",&a,&b,&c);
x=a, y=b, z=c;
}
friend point3D operator -(const point3D &a,const point3D &b)
{
return point3D(a.x-b.x,a.y-b.y,a.z-b.z);
}
friend point3D operator +(const point3D &a,const point3D &b)
{
return point3D(a.x+b.x,a.y+b.y,a.z+b.z);
}
}; struct line
{
long double a,b,c,d;
point3D u,v;
}l[33]; long double vlen(point3D a)//向量长度
{
return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
} long double dis(point3D a,point3D b)//两点距离
{
long double x=a.x-b.x;
long double y=a.y-b.y;
long double z=a.z-b.z;
return sqrt(x*x+y*y+z*z);
} point3D xmult(point3D u,point3D v)//叉积,法向量
{
point3D ret;
ret.x=u.y*v.z-v.y*u.z;
ret.y=u.z*v.x-u.x*v.z;
ret.z=u.x*v.y-u.y*v.x;
return ret;
} long double dmult(point3D u,point3D v)//点积
{
return u.x*v.x+u.y*v.y+u.z*v.z;
} point3D get_faline(point3D a,point3D b,point3D c)//平面的法向量
{
return xmult(b-a,c-a);
} bool dian_inline(point3D a,point3D b,point3D c)//判断三点共线
{
return vlen(xmult(b-a,c-a))<eps;
} bool dian_inmian(point3D a,point3D b,point3D c,point3D d)//四点公面
{
return zero(dmult(get_faline(a,b,c),d-a));
} long double xian_xian(line l1,line l2)//直线到直线的距离
{
point3D n=xmult(l1.u-l1.v,l2.u-l2.v);//法向量
return fabs(dmult(l1.u-l2.u,n))/vlen(n);
} point3D a,b,c,d; long double F1(point3D a,point3D b)
{
return ((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)+(b.z-a.z)*(b.z-a.z));
} long double F2()
{
return ((b.x-a.x)*(d.x-c.x)+(b.y-a.y)*(d.y-c.y)+(b.z-a.z)*(d.z-c.z));
} long double F3ab(point3D a,point3D b)
{
return ((b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y)+(b.z-a.z)*(c.z-a.z));
} long double F3cd(point3D c,point3D d)
{
return ((d.x-c.x)*(c.x-a.x)+(d.y-c.y)*(c.y-a.y)+(d.z-c.z)*(c.z-a.z));
} int main()
{
int T;
cin>>T;
while(T--)
{
a.input(); b.input(); c.input(); d.input();
line l1,l2;
l1.u=a; l1.v=b;
l2.u=c; l2.v=d;
printf("%.6lf\n",(double)xian_xian(l1,l2));
long double x[6];
long double xh1,xh2;
xh1=F3ab(a,b)*F1(c,d)-F3cd(c,d)*F2();
xh2=F1(a,b)*F1(c,d)-F2()*F2();
x[0]=(b.x-a.x)*xh1/xh2+a.x;
x[1]=(b.y-a.y)*xh1/xh2+a.y;
x[2]=(b.z-a.z)*xh1/xh2+a.z; long double xx1,xx2,xxx;
xx1=F3cd(c,d)*F1(a,b)-F3ab(a,b)*F2();
xx2=F2()*F2()-F1(a,b)*F1(c,d);
xxx=xx1/xx2;
x[3]=(d.x-c.x)*xxx+c.x;
x[4]=(d.y-c.y)*xxx+c.y;
x[5]=(d.z-c.z)*xxx+c.z; for(int i=0;i<5;i++)
printf("%.6lf ",(double)x[i]);
printf("%.6lf\n",(double)x[5]);
}
return 0;
}

HDU 4741 Save Labman No.004 2013 ACM/ICPC 杭州网络赛的更多相关文章

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

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

  2. 2013 ACM/ICPC 杭州网络赛C题

    题意:驴和老虎,在一个矩阵的两个格子里,有各自的起始方向.两者以相同的速度向前移动,前方不能走时驴总是向右,老虎总是向左.他们不能超出矩阵边界也不能走自己走过的格子(但可以走对方走过的格子).如果不能 ...

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

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

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

  5. 2013 ACM/ICPC 成都网络赛解题报告

    第三题:HDU 4730 We Love MOE Girls 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4730 水题~~~ #include < ...

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

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

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

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

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

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

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

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

随机推荐

  1. python property装饰器

    直接上代码: #!/usr/bin/python #encoding=utf-8 """ @property 可以将python定义的函数“当做”属性访问,从而提供更加友 ...

  2. 磁盘性能,你可能不知道的IOPS计算方法

    每个I/O 请求到磁盘都需要若干时间.主要是因为磁盘的盘边必须旋转,机头必须寻道.磁盘的旋转常常被称为”rotational delay”(RD),机头的移动称为”disk seek”(DS).一个I ...

  3. mysql 创建表字段类型笔记

    1.字段联合唯一,unique(ServerVersion , MobileVersion, MobileType) .并且mysql设置多个字段为主键是起不到约束唯一的作用. 2.二进制用 BLOB ...

  4. java ee环境搭建

    1.安装java(tm)2 platform 2.下载安装Java EE SDK 版本:Java Platform,Enterprise Edition 7 SDK (with JDK 7u45) 下 ...

  5. c语言各类问题 代码

    定义一个结构体,有两个成员变量,一个整型的n,一个字符型的c,利用结构体类型声明一个具有5个元素的数组,并随机初始化,根据成员变量n进行从小到大排序,然后输出 冒泡排序然后 在输出结构体#includ ...

  6. 安装VMware vSphere 的目的就是在一台物理服务器上安装很多很多的虚拟机

    版权声明:本文为博主原创文章,未经博主允许不得转载. 我们安装VMware vSphere 的目的就是在一台物理服务器上安装很多很多的虚拟机,我们可以通过VMware vSphere Client直接 ...

  7. oracle,如何查看视图结构,获得视图中的字段名称、字段类型、字段长度等。

    需要获得一个视图中的字段名称.字段类型.字段长度等信息,该如何编写sql语句.通过select * from user_views可以获得给定用户下所有的视图名称了,但是没找到如何获取视图结构的解决方 ...

  8. 关于DLL搜索路径顺序的一个问题

    DLL的动态链接有两种方法.一种是加载时动态链接(Load_time dynamic linking).Windows搜索要装入的DLL时,按以下顺序:应用程序所在目录→当前目录→Windows SY ...

  9. java面试题系列11

    华为的JAVA面试题 QUESTION NO: 1 publicclass Test1 {       publicstaticvoid changeStr(String str){         ...

  10. xen虚拟机操作整理

    1,登陆物理机器 2,查看物理机建立虚拟机的列表 root:~ # xm li Name ID Mem VCPUs State Time(s) Domain-0 0 49450 8 r----- 52 ...