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/Others)
Total Submission(s): 624 Accepted Submission(s): 154
During the research in World Line Alpha, the assistant of Dr. Kyouma, also the Labman No.004, Christina dies. Dr. Kyouma wants to save his assistant. Thus, he has to build a Time Tunnel to jump from World Line Alpha to World Line Beta in which Christina can be saved. More specifically, a Time Tunnel is a line connecting World Line Alpha and World Line Beta. In order to minimizing the risks, Dr. Kyouma wants you, Labman No.003 to build a Time Tunnel with shortest length.
Each case contains only one line with 12 float numbers (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4), correspondingly indicating two points in World Line Alpha and World Line Beta. Note that a World Line is a three-dimensional line with infinite length.
Data satisfy T <= 10000, |x, y, z| <= 10,000.
The first line contains one float number, indicating the length of best Time Tunnel.
The second line contains 6 float numbers (xa, ya, za), (xb, yb, zb), seperated by blank, correspondingly indicating the endpoints of the best Time Tunnel in World Line Alpha and World Line Beta.
All the output float number should be round to 6 digits after decimal point. Test cases guarantee the uniqueness of the best Time Tunnel.
1 0 1 0 1 1 0 0 0 1 1 1
0.500000 0.500000 1.000000 0.666667 0.666667 0.666667
详细公式见:
http://blog.sina.com.cn/s/blog_a401a1ea0101ij9z.html
然后直接使用公式就可以了。
/* ***********************************************
Author :kuangbin
Created Time :2013/9/15 星期日 13:01:15
File Name :2013杭州网络赛\1004.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
struct Point
{
double x,y,z;
Point(double _x = ,double _y = ,double _z = )
{
x = _x;
y = _y;
z = _z;
}
Point operator +(const Point &b)const
{
return Point(x + b.x, y + b.y,z + b.z);
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y,z - b.z);
}
Point operator /(double k)
{
return Point(x/k,y/k,z/k);
}
Point operator *(double k)
{
return Point(x*k,y*k,z*k);
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y + z*b.z;
}
Point operator ^(const Point &b)const
{
return Point(y*b.z - z *b.y,z*b.x - x*b.z, x*b.y - y * b.x);
}
void input()
{
scanf("%lf%lf%lf",&x,&y,&z);
}
void output()
{
printf("%.6lf %.6lf %.6lf",x,y,z);
}
};
double dis(Point a,Point b)
{
return sqrt((a.x - b.x) * (a.x- b.x) + (a.y - b.y) *(a.y - b.y) + (a.z - b.z)*(a.z - b.z));
}
double norm(Point a)
{
return sqrt(a.x *a.x + a.y *a.y + a.z * a.z);
}
Point A,B,C,D;
Point mid1,mid2;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
A.input();
B.input();
C.input();
D.input();
Point p1 = (B-A);
Point p2 = (D-C);
Point p = p1^p2; double dd = (p*(A-C))/norm(p);
dd = fabs(dd);
printf("%.6lf\n",dd); double t1 = ( (C-A)^p2 )*(p1^p2);
t1 /= norm(p1^p2)*norm(p1^p2);
double t2 = ( (C-A)^p1 )*(p1^p2);
t2 /= norm(p1^p2)*norm(p1^p2);
mid1 = A + (p1 * t1);
mid2 = C + (p2 * t2);
mid1.output();
printf(" ");
mid2.output();
printf("\n"); }
return ;
}
HDU 4741 Save Labman No.004 (2013杭州网络赛1004题,求三维空间异面直线的距离及最近点)的更多相关文章
- 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 4762 Cut the Cake (2013长春网络赛1004题,公式题)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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 4747 Mex (2013杭州网络赛1010题,线段树)
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- HDU 4739 Zhuge Liang's Mines (2013杭州网络赛1002题)
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 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杭州网络赛D题HDU 4741(计算几何 解三元一次方程组)
Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- CSS3 - chrome,傲游,360极速浏览器不支持小于12px的字号的解决办法
google流量器chrome,傲游,360极速浏览器都是基于webkit内核浏览器,默认不支持小于font-size小于12px 的字号,即定义font-size小于12px时会发现字体大小依然是1 ...
- Servlet笔记8--乱码解决方案
乱码解决方案: 代码详解: package com.bjpowernode.javaweb.servlet; import java.io.IOException; import javax.serv ...
- python3光学字符识别模块tesserocr与pytesseract
OCR,即Optical Character Recognition,光学字符识别,是指通过扫描字符,然后通过其形状将其翻译成电子文本的过程,对应图形验证码来说,它们都是一些不规则的字符,这些字符是由 ...
- linux C守护进程编写
linux编程-守护进程编写 守护进程(Daemon)是运行在后台的一种特殊进程.它独立于控制终端并且周期性地执行某种任务或等待 处理某些发生的事件.守护进程是一种很有用的进程. Linux的大多数服 ...
- 解决cef中title不现实tooltip的问题
本文转自:https://blog.csdn.net/hu1340748/article/details/79030569 感谢感谢 最近在使用chromiumFX做项目,突然发现页面标签中的titl ...
- spring-dao.xml 模板
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 《jquery实战》javascript 必知必会(2)
A2 一等公民函数 在传统 OO 语言里,对象包含数据和方法.这些语言里,数据和方法通常是不同的概念:javascript另辟蹊径. 与其他 js 的类型一样,函数可以作为对象处理,如String.N ...
- **如何让CI框架支持service层
http://www.bitscn.com/pdb/php/201411/404708.html 大家知道CodeIgniter框架式MVC分层的,通常大家把业务逻辑写到Controller中,而Mo ...
- Java编程的逻辑 (26) - 剖析包装类 (上)
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...
- Learning coding online
A lot of online courses for coding skills are available nowadays, both free and non-free. I will col ...