hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]
// Time 234 ms; Memory 244 K
#include<iostream>
#include<cstdio>
#include<cmath> using namespace std; typedef struct point
{
double x,y,z;
point(double xx=0,double yy=0,double zz=0):x(xx),y(yy),z(zz){}
}vector;
vector operator - (point a,point b)
{
return vector(a.x-b.x,a.y-b.y,a.z-b.z);
}
point operator + (point a,vector b)
{
return point(a.x+b.x,a.y+b.y,a.z+b.z);
}
vector operator * (vector a,double b)
{
return vector(a.x*b,a.y*b,a.z*b);
}
double dot(vector a,vector b)
{
return a.x*b.x+a.y*b.y+a.z*b.z;
}
double len(vector a)
{
return sqrt(dot(a,a));
}
vector cross(vector a,vector 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 inter(point a,point b,point c,point d,point e)
{
point fa=cross(b-a,c-a);
double t=dot(fa,a-d)/dot(fa,e-d);
return d+(e-d)*t;
}
vector resize(vector a,double b)
{
b/=len(a);
return a*b;
}
point ptol(point o,point a,point b)
{
point fa=cross(a-o,b-o);
point vec=cross(b-a,fa);
return o+resize(vec,len(fa)/len(b-a));
}
void gc(point a,point b,point c,point d,point &p1,point &p2)
{
point e=d+cross(a-b,c-d);
p1=inter(c,d,e,a,b);
p2=ptol(p1,c,d);
} int main()
{
int t;
point a,b,c,d,p,q;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.z,&b.x,&b.y,&b.z);
scanf("%lf%lf%lf%lf%lf%lf",&c.x,&c.y,&c.z,&d.x,&d.y,&d.z);
gc(a,b,c,d,p,q);
double l=len(p-q);
printf("%.6lf\n",l);
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",p.x,p.y,p.z,q.x,q.y,q.z);
}
return 0;
}
hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]的更多相关文章
- 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杭州网络赛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 ...
- 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 ...
- HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )
空间异面直线的距离直接套模板. 求交点:求出两条直线的公共法向量,其中一条直线与法向量构成的平面 与 另一条直线 的交点即可.还是套模板o(╯□╰)o 1.不会有两条线平行的情况. 2.两条直线可能相 ...
- HDU 4741 Save Labman No.004 (几何)
题意:求空间两线的最短距离和最短线的交点 题解: 线性代数和空间几何,主要是用叉积,点积,几何. 知道两个方向向量s1,s2,求叉积可以得出他们的公共垂直向量,然后公共垂直向量gamma和两线上的点形 ...
随机推荐
- codeforces 553D . Nudist Beach 二分
题目链接 有趣的题. 给一个图, n个点m条边. 有k个点不可选择. 现在让你选出一个非空的点集, 使得点集中strength最小的点的strength最大. strength的定义:一个点周围的点中 ...
- 编写一个程序实现strcat函数的功能
写自己的strcat函数------→mycat #include <stdio.h> #include <string.h> #define N 5 char *mycat( ...
- 【java】for循环输出数字金字塔
输出下列数字金字塔. 1 121 123211234321 public class deng { public static void main(String args[]) { int n ...
- mac电脑批量解压android apk文件图形化工具--apkDecode
mac电脑apk文件解压软件,简单的用图形界面将apktools包装了下,使用起来非常简单,可以将apk文件批量解压缩,方便大家查看一些东东,仅供学习目的. 使用步骤如下: 1 下载apkDecode ...
- Android官方终于支持 Navigation Drawer(导航抽屉)模式
在2013 google IO当天,Android团的更新了Support库,新版本(V13)的Support库中新加入了几个比较重要的功能. 添加 DrawerLayout 控件,支持创建 Nav ...
- C. Table Decorations(Codeforces Round 273)
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...
- golang 并发之协程及通道
一.概述 在golang中,每个并发执行单元称为goroutine,当程序启动时,main函数在一个单独的goroutine中运行,(main goroutine).新的goroutine会用go语句 ...
- api文档生成工具 C#
要为编写的程序编写文档,这是件费力气的事,如果能自动生成就好了. 不怕做不到,就怕想不到.这不,搜索到了Sandcastle 比较好的参考文章: 1.Sandcastle官方网址: http://sh ...
- 【Java并发编程】并发编程大合集-值得收藏
http://blog.csdn.net/ns_code/article/details/17539599这个博主的关于java并发编程系列很不错,值得收藏. 为了方便各位网友学习以及方便自己复习之用 ...
- CentOS修改系统默认语言与编码
有时候在安装CentOS无意中把默认语言设置为中文,而部分SSH软件不支持中文编码,所以在远程管理的时候会出现些乱码的现象. 如何修改CentOS的默认语言呢? 请先使用root权限帐户登陆 一. ...