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 ...
随机推荐
- 嵌入式系统 Boot Loader
基于嵌入式系统中的 OS 启动加载程序 ―― Boot Loader 的概念.软件设计的主要任务以及结构框架等内容.
- 在 win 10 中使用sql 2012 附加低版本数据失败的解决办法。
随着win 10 的发布,我也尝试把自己的笔记本升级下,体验win10,由于自己电脑好长时间没有管理过,东西比较乱,一激动就格式了硬盘.但是所有的资料都丢失了,不过我都提前备份到网盘上.好了,废话不多 ...
- HTTP 错误
问题描述: HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. 解决办法: win7 ...
- Java 网络编程(四) InetAddress类
链接地址:http://www.cnblogs.com/mengdd/archive/2013/03/09/2951895.html Java 网络编程(四) InetAddress类 InetAdd ...
- Javaweb统计在线人数的小栗子
最近在学习Javaweb相关的内容(不黑不吹之前对web开发零基础),下面通过一个统计在线人数的小栗子讲讲Servlet监听器吧 开发环境 eclipse tomcat 7 先说说这个小栗子的构思: ...
- 5.7.1.2 eval() 方法
现在我们介绍最后一个方法,这大概是ECMAScript语言中最强大的一个方法:eval().eval()方法就想一个完整的ECMAScript解析器,它只接受一个参数,即要执行的ECMAScript( ...
- QT Sleep(最佳的平衡:一边发送消息,一边睡眠)
转自:http://xiangjie88.iteye.com/blog/898417 sleep()//秒msleep()//毫秒usleep()//微秒以前为了模拟鼠标点击用过这些函数,可以让进程中 ...
- HDU 3571 N-dimensional Sphere
高斯消元,今天数学死了无数次…… #include <cstdio> #include <cstring> #include <cmath> #include &l ...
- 获取中央气象台API 完整城市列表简单方式
activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...
- TCP编程的一个小例子
TCP程序的服务器端与客户端的流程图 例子:服务器端等待客户端连接,若连接成功,则用户可以通过客户端向服务器端发送任意字符串,服务器端在收到字符串后,输出相关信息,在把接受到的字符串重新发生给客户端. ...