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 ...
随机推荐
- 简洁的PHP操作SQLite类
SQLite是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了. ...
- 3D空间坐标系转换复习
模型坐标系:ModelSpace 即模型本身为中心 模型本身自己 世界坐标系:WorldSpace 世界坐标系 整个世界 视角坐标系: ViewSpace 眼睛看到的范 ...
- 立体像对DEM提取
版权声明:本教程涉及到的数据仅练习使用,禁止用于商业用途. 目录 1.概述 2.详细操作步骤 第一步:输入立体像对 第二步:定义地面控制点 第三步:定义连接点 第四步:设定DEM提取参数 第五步:输出 ...
- css学习笔记二
下面来总结一下盒子模型,流式布局,浮动布局,层布局(定位布局). 1.盒子模型 有二种:IE盒子模型 和 标准w3c盒子模型 1)IE的盒子模型的content包含了padding和border 2) ...
- pywebkitgtk安装出现的问题
configure 文件里 print sys.prefix 等不能支持python3的原因 依据http://blog.csdn.net/jklfjsdj79hiofo/article/detail ...
- Objective-C官方文档翻译 Block
版权声明:原创作品,谢绝转载!否则将追究法律责任. 一个Objective-c类定义了一个对象结合数据相关的行为.有时候,这使得他有意义的表达单个任务或者单元的行为.而不是集合的方法. blocks是 ...
- 关于在App_Code文件夹自定义类中Session无法使用
由于前台页面需要调用App_Code中自定义类的函数,但在自定义类中找不到Session,解决方法如下: 新建一个类session,并自己定义函数GetSession(),引用命名空间 System. ...
- errorPlacement的位置问题
做一个前端的验证,使用了JQUERY.Validate 在errorPlacement上纠结了半天: 百度大多数都是一个答案: errorPlacement: function(error, elem ...
- HiveQL与SQL区别
转自:http://www.aboutyun.com/thread-7327-1-1.html 1.Hive不支持等值连接 SQL中对两表内联可以写成:select * from dual a,dua ...
- win7 ie10输入网址显示无法显示此页问题的解决
忽然又一天,非常奇怪,所有的浏览器都无法访问网页,直接输入IP也是不行. 本人试过各种方法,包括用360进行修复:清除%temp%下文件:看是否设错了dns, 升级和修复IE,重新注册ie相关的dll ...