HDU 4741 Save Labman No.004 2013 ACM/ICPC 杭州网络赛
传送门: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 杭州网络赛的更多相关文章
- hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]
// Time 234 ms; Memory 244 K #include<iostream> #include<cstdio> #include<cmath> u ...
- 2013 ACM/ICPC 杭州网络赛C题
题意:驴和老虎,在一个矩阵的两个格子里,有各自的起始方向.两者以相同的速度向前移动,前方不能走时驴总是向右,老虎总是向左.他们不能超出矩阵边界也不能走自己走过的格子(但可以走对方走过的格子).如果不能 ...
- 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 ...
- hdu 4741 Save Labman No.004异面直线间的距离既构成最小距离的两个端点
Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 2013 ACM/ICPC 成都网络赛解题报告
第三题:HDU 4730 We Love MOE Girls 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4730 水题~~~ #include < ...
- hdu 4741 Save Labman No.004(2013杭州网络赛)
http://blog.sina.com.cn/s/blog_a401a1ea0101ij9z.html 空间两直线上最近点对. 这个博客上给出了很好的点法式公式了...其实没有那么多的tricky. ...
- HDU 4741 Save Labman No.004(计算几何)
题目链接 抄的模版...mark一下. #include <iostream> #include <cstring> #include <cstdio> #incl ...
- [HDU 4741]Save Labman No.004[计算几何][精度]
题意: 求两条空间直线的距离,以及对应那条距离线段的两端点坐标. 思路: 有一个参数方程算最短距离的公式, 代入求即可. 但是这题卡精度... 用另外的公式(先算出a直线上到b最近的点p的坐标, 再算 ...
- hdu 4741 Save Labman No.004 (异面直线的距离)
转载学习: #include <cstdio> #include <cstdlib> #include <cstring> #include <algorit ...
随机推荐
- 最近adt升级引起的问题
其实也不知道是什么原因引起的,因为 之前安装的adt就是23.0.3的版本,但是最近突然创建安卓工程时出现了如下问题 D:\workspace\appcompat_v7\res\values-v21\ ...
- slf4j+log4j配置(Maven)
首先配置Maven依赖 <!-- http://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 --> <dependency& ...
- 【转】OpenCV与CxImage转换(IplImage)、IplImage QImage Mat 格式互转
最近由于在项目中用到了Opencv库,但是为了更好的显示图像还是使用了Cximage库,它可以快捷地存取.显示.转换各种图像.Opencv库用于高级图像处理与识别.为了使Cximage图像与Openc ...
- BZOJ 1005: [HNOI2008]明明的烦恼( 组合数学 + 高精度 )
首先要知道一种prufer数列的东西...一个prufer数列和一颗树对应..然后树上一个点的度数-1是这个点在prufer数列中出现次数..这样就转成一个排列组合的问题了.算个可重集的排列数和组合数 ...
- 关于$.ajax的请求格式
1 $.ajax({ 2 url: "http://localhost:5311/UserService.asmx/GetLoginId",//请求的URL 3 type: &qu ...
- Android Gradle 配置选项合集
//让gradle 引入构建安卓app的插件 apply plugin: 'com.android.application' //自定义变量, 使用的时候不需要 ext 前缀 ext { minSdk ...
- python函数abs()
详解: 返回绝对值 参数可以是:负数.正数.浮点数或者长整形 实例: abs(-1.2) #返回 1.2 abs(1.2) #返回 1.2 abs(-11216.5) #返回 11216.5 abs( ...
- Page Cache, the Affair Between Memory and Files
Previously we looked at how the kernel manages virtual memory for a user process, but files and I/O ...
- android-适配Adapter
Adapter是把数据和用户界面视图绑定到一起的桥梁类,负责创建用来表示父视图中的每一个条目的子视图,并提供对底层数据的访问. public class MainActivity extends Ac ...
- 帝国cms7.2自定义列表建立tag效果 代码 教程
统计记录:(如:select count(*) as total from phome_ecms_news where classid=1 and checked=1) 注:这句SQL的意思是查找统计 ...