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 ...
随机推荐
- AngularJS Directive 学习笔记
指令 Directive 指令要点 大漠老师的教学节点 解析最简单的指令 hello: 匹配模式 restrict 解析最简单的指令 hello: template.tempmlateUrl.$tem ...
- 开启新的activity获取它的返回值
1.开始界面 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...
- Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (二) —— SQLite
SQLite是一种转为嵌入式设备设计的轻型数据库,其只有五种数据类型,分别是: NULL: 空值 INTEGER: 整数 REAL: 浮点数 TEXT: 字符串 BLOB: 大数据 在SQLite中, ...
- c++ primer plus 习题答案(4)
p333.3 #include<iostream> #include<cstdlib> #include<cstring> #include<string&g ...
- cmd命令添加一个应用程序到防火墙例外项中
windows+r 键打开运行 输入cmd按回车 把下列命令在cmd中点击右键粘贴进去,按回车,即可添加到防火墙例外程序列表中. netsh advfirewall firewall delete r ...
- Yii2.0中文开发向导——删除数据
直接 model 删除 $model = User::find($id); $model->delete(); 带有条件的删除 $connection ->createCommand() ...
- php制作数据字典
/** * 生成mysql数据字典 */ header("Content-type:text/html;charset=utf-8"); // 配置数据库 $database = ...
- A Byte of Python 笔记(2)基本概念:数、字符串、转义符、变量、标识符命名、数据类型、对象
第4章 基本概念 字面意义上的常量 如5.1.23.9.23e-3,或者 'This is a string'."It's a string!" 字符串等 常量,不能改变它的值 数 ...
- 13-C语言字符串函数库
目录: 一.C语言字符串函数库 二.用命令行输入参数 回到顶部 一.C语言字符串函数库 1 #include <string.h> 2 字符串复制 strcpy(参数1,参数2); 参数1 ...
- win7下Java环境变量配置及说明
在官网上下载与操作系统对应的JDK(http://www.oracle.com/index.html) 比如我的安装路径是E:\jdk1.7.0_51\JDK 右击计算机---->属性----& ...