2013杭州网络赛D题HDU 4741(计算几何 解三元一次方程组)
Save Labman No.004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 979 Accepted Submission(s): 306
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
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std; int main()
{
int tes;
double x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4;
double a1,b1,c1,a2,b2,c2;
scanf("%d",&tes);
while(tes--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&z1,&x2,&y2,&z2,&x3,&y3,&z3,&x4,&y4,&z4);
a1=x2-x1,b1=y2-y1,c1=z2-z1; //第一条直线
a2=x4-x3,b2=y4-y3,c2=z4-z3; //第二条直线
double k1,k2;
double p1,p2,p3; //p点
double q1,q2,q3; //q点
double s1,s2,s3; //前两条直线的公垂线
s1=b1*c2-b2*c1;
s2=c1*a2-c2*a1;
s3=a1*b2-a2*b1;
//方程组转化为
//t1*k1+t2*k2=t3,m1*k1+m2*k2=m3;
double t1,t2,t3,m1,m2,m3;
t1=s2*a1-s1*b1,t2=s1*b2-s2*a2,t3=s1*(y1-y3)-s2*(x1-x3);
m1=s3*a1-s1*c1,m2=s1*c2-s3*a2,m3=s1*(z1-z3)-s3*(x1-x3);
k1=(t3*m2-m3*t2)/(t1*m2-m1*t2);
k2=(t3*m1-m3*t1)/(t2*m1-m2*t1); p1=k1*a1+x1,p2=k1*b1+y1,p3=k1*c1+z1,
q1=k2*a2+x3,q2=k2*b2+y3,q3=k2*c2+z3;
double dis=sqrt((p1-q1)*(p1-q1)+(p2-q2)*(p2-q2)+(p3-q3)*(p3-q3));
printf("%.6lf\n",dis);
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",p1,p2,p3,q1,q2,q3);
}
return 0;
} /*
23
0 0 0 0 0 1 1 0 0 0 1 0
*/
//234MS 248K
2013杭州网络赛D题HDU 4741(计算几何 解三元一次方程组)的更多相关文章
- 2013杭州网络赛C题HDU 4640(模拟)
The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 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 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 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 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 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)
Walk Through Squares Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
随机推荐
- java反射机制(笔记)
java反射机制就是获取出class的相应方法 例如 获取构造函数: 模版: Class test = Class.forName("cn.test.Person");//得到相应 ...
- charset
<meta charset="UTF-8" /> 这是html5的写法. <meta http-equiv=“content-type” content=“tex ...
- Umbraco扩展开发
国内Umbraco方面的资料很少,搜集到一些国外的优秀项目或插件.记录下来,便于日后使用: backoffice:https://github.com/TimGeyssens 后台扩展UI,可以在这里 ...
- 搭建Android开发环境之——Android4.0.3, 4.1, 4.2, 4.3, 4.x,及升级 ADT(22.0.5)和SDK(22.x)
1.首先要下载相关的软件 1). JDK 6 以上 2). eclipse( Version 3.6.2 or higher ) 点击下载 3). SDK(android-sdk_r18-windo ...
- Windows Azure 网站:应用程序字符串和连接字符串的工作原理
编辑人员注释:本文章由 Windows Azure 网站团队的首席项目经理 Stefan Schackow 撰写. Windows Azure 网站上有一个方便的功能,即开发人员可将 Azure 中的 ...
- 利用sass构建组件化的ui库
创建公用的Sass项目模板 在做项目时,不管什么项目,他们之间总是有一些可以共用的部分.比如说重置样式.公用样式.模块组件.UI库等.那么在Sass项目中也是如此.为了避免在每个项目中做一些相同的事情 ...
- css Tab选项卡
css tab 选项卡据说有2中实现方式 1. target css3 2. 描点 2的 核心原理是利用描点显示问题(描点父级 overflow). <style> body,div,ul ...
- git 使用随笔
/*将远端库git@github.com:myrepo/base.git从远端clone到本地*/git clone git@github.com:myrepo/base.git /*克隆版本库的时候 ...
- Asp.Net MVC 控制器
原文链接:http://www.asp.net/learn/mvc/ 这篇教程探索了ASP.NET MVC控制器(controller).控制器动作(controller action)和动作结果(a ...
- csapp lab2 bomb 二进制炸弹《深入理解计算机系统》
bomb炸弹实验 首先对bomb这个文件进行反汇编,得到一个1000+的汇编程序,看的头大. phase_1: 0000000000400ef0 <phase_1>: 400ef0: 48 ...