hdu 4741 Save Labman No.004(2013杭州网络赛)
http://blog.sina.com.cn/s/blog_a401a1ea0101ij9z.html
空间两直线上最近点对。
这个博客上给出了很好的点法式公式了。。。其实没有那么多的tricky。。。不知到别人怎么错的。。。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<sstream>
#include<vector>
#include<string>
#include<cstdio>
#include<bitset>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define MP make_pair
#define eps 1e-10
using namespace std; struct Point
{
double x, y, z;
Point(double x=0, double y=0, double z=0) : x(x), y(y),z(z){}
};
typedef Point Vector; Vector operator + (Vector a, Vector b) { return Vector(a.x+b.x, a.y+b.y, a.z+b.z); };
Vector operator - (Vector a, Vector b) { return Vector(a.x-b.x, a.y-b.y, a.z-b.z); };
Vector operator * (Vector a, double p) { return Vector(a.x*p, a.y*p, a.z*p); }
Vector operator / (Vector a, double p) { return Vector(a.x/p, a.y/p, a.z/p); } double Dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
double Length(Vector a) { return sqrt(Dot(a, a)); }
Vector Cross(Point a, Point 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 a1, b1, a2, b2;
int main()
{
int n;
scanf("%d", &n);
while(n--)
{
scanf("%lf%lf%lf", &a1.x, &a1.y, &a1.z);
scanf("%lf%lf%lf", &b1.x, &b1.y, &b1.z);
scanf("%lf%lf%lf", &a2.x, &a2.y, &a2.z);
scanf("%lf%lf%lf", &b2.x, &b2.y, &b2.z);
Vector v1 = (a1-b1), v2 = (a2-b2);
Vector N = Cross(v1, v2);
Vector ab = (a1-a2);
double ans = Dot(N, ab) / Length(N);
Point p1 = a1, p2 = a2;
Vector d1 = b1-a1, d2 = b2-a2;
Point ans1, ans2;
double t1, t2;
t1 = Dot((Cross(p2-p1, d2)), Cross(d1, d2));
t2 = Dot((Cross(p2-p1, d1)), Cross(d1, d2));
double dd = Length((Cross(d1, d2)));
t1 /= dd*dd;
t2 /= dd*dd;
ans1 = (a1 + (b1-a1)*t1);
ans2 = (a2 + (b2-a2)*t2);
printf("%.6f\n", fabs(ans));
printf("%.6f %.6f %.6f ", ans1.x, ans1.y, ans1.z);
printf("%.6f %.6f %.6f\n", ans2.x, ans2.y, ans2.z);
}
return 0;
}
hdu 4741 Save Labman No.004(2013杭州网络赛)的更多相关文章
- HDU 4741 Save Labman No.004 2013 ACM/ICPC 杭州网络赛
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4741 题意:给你两条异面直线,然你求着两条直线的最短距离,并求出这条中垂线与两直线的交点. 需要注意的是 ...
- hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]
// Time 234 ms; Memory 244 K #include<iostream> #include<cstdio> #include<cmath> u ...
- 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 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4741 Save Labman No.004异面直线间的距离既构成最小距离的两个端点
Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 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 ...
- HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )
空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...
随机推荐
- Android SQLite系列
转:http://blog.csdn.net/liuhe688/article/details/6715983 Android中如何使用SQLite. 现在的主流移动设备像Android.iPhone ...
- <a>标签中 href="/" 和 hideFocus="true"
一:href="/" 连接到根目录 这是相对路径的根目录表示方法 可以写为 http://class.qq.com/">腾讯精品课 (绝对路径写法) 也可以为 腾讯 ...
- 深入学习PE文件(转)
PE文件是Win32的原生文件格式.每一个Win32可执行文件都遵循PE文件格式.对PE文件格式的了解可以加深你对Win32系统的深入理解. 一. 基本结构. 上图便是PE文件的基本结构.(注意:DO ...
- Android Studio设置自动编译工程
- Android关机流程源码分析
上一篇文章Android 开关机动画显示源码分析详细介绍了开关机动画的显示过程,Android系统开机时,在启动SurfaceFlinger服务过程中通过Android属性系统方式来启动bootani ...
- Unix/Linux环境C编程入门教程(17) Gentoo LinuxCCPP开发环境搭建
1. Gentoo Linux是一套通用的.快捷的.完全免费的Linux发行,它面向开发人员和网络职业人员.与其他发行不同的是,Gentoo Linux拥有一套先进的包管理系统叫作Portage.在B ...
- openstack 的 policy 问题。
想写nova的policy的实现, 但是发现网上,有人写的很不错了. ref: http://blog.csdn.net/hackerain/article/details/8241691 但是,po ...
- background-size:的认识;
background-size:100%;其实是元素的背景图片的宽度和元素宽度相同,高度auto: 也可理解为:background-size:100% auto; 而background:cover ...
- getHibernateTemplate().saveOrUpdate 不运行
在ssh中使用hibernateTemplate来保存对象的时候.出现一个问题,就是saveOrUpdate既不报错.也不在控制台打印插入语句,也不想数据库插入数据. 问题解决: 这个是事务的原因.检 ...
- Eclipse debug ‘Source not found’
用Eclispe进行Debug时一直被一个问题所困扰:Source not found. 问题产生的原因是调试进入了一个没有源代码的jar包里. 简短说明: Edit Source Lookup Pa ...