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 ...
随机推荐
- 数据库课本SQL第三章答案
3 .用 sQL 语句建立第二章习题 5 中的 4 个表. 答: 对于 S 表: S ( SNO , SNAME , STATUS , CITY ) ; 建 S 表: CREATE TABLE S ( ...
- Flink资料(4) -- 类型抽取和序列化
类型抽取和序列化 本文翻译自Type Extraction and Serialization Flink处理类型的方式比较特殊,包括它自己的类型描述,一般类型抽取和类型序列化框架.该文档描述这些概念 ...
- python相似模块用例(一)
一:threading VS Thread 众所周知,python是支持多线程的,而且是native的线程,其中threading是对Thread模块做了包装,可以更加方面的被使用,threading ...
- [C#]Windows文件分类器小程序
我平时习惯把各种文件都下载在`下载`文件夹中,时间久了,文件多了,想要找个文件就不那么方便了.于是我就想自己写一个小程序来实现下载文件的自动整理.我想到的文件分类方式是按照文件扩展名分类:把各文件移动 ...
- ArcEngine 9.3 学习笔记(六):图层符号化(COlorRamp,MarkerSymbol,LineSymbol,FillSymbol,TextSymbol,3DChartSymbol,使用ServerStyle符号库,FeatureRender,RasterRender)
第四章 图层符号化 AE9.3 提供了SymbologyControl控件,用于显示ARCGIS符号库中的符号. 组件库中的组件对象分为Color(颜色),Symbol(符号),Render(渲染)三 ...
- C++中输入输出流及文件流操作笔记
1.流的控制 iomanip 在使用格式化I/O时应包含此头文件. stdiostream 用于混合使用C和C + +的I/O机制时,例如想将C程序转变为C++程序 2.类 ...
- javascript数组去重算法-----5
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Effective Objective-C 读书笔记
一本不错的书,给出了52条建议来优化程序的性能,对初学者有不错的指导作用,但是对高级阶段的程序员可能帮助不是很大.这里贴出部分笔记: 第2条: 使用#improt导入头文件会把头文件的内容全部暴露到目 ...
- Android 匿名共享内存C++接口分析
在上一篇Android 匿名共享内存C接口分析中介绍了Android系统的匿名共享内存C语言访问接口,本文在前文的基础上继续介绍Android系统的匿名共享内存提供的C++访问接口.在C++层通过引入 ...
- 使用window.postMessage实现跨域通信
JavaScript由于同源策略的限制,跨域通信一直是棘手的问题.当然解决方案也有很多: document.domain+iframe的设置,应用于主域相同而子域不同: 利用iframe和locati ...