http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28235#problem/B

题目大意: 有两个同时再空间中匀速运动的导弹,告诉一个时间以及各自的初始坐标和该时间时的坐标,求运动过程中的最短距离
解题思路:  求出相对初位置、相对速度,则答案就是原点到射线型轨迹的距离,注意是射线!!!
//*******************************************************************************
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
#define eps 1e-8 int dcmp(double x){
if(fabs(x)<eps)return ;
else return x< ? -:;
} struct Point3{
double x,y,z;
Point3(double x=,double y=,double z=):x(x),y(y),z(z){} };
bool operator==(const Point3& a,const Point3& b){
return dcmp(a.x-b.x)== && dcmp(a.y-b.y)== && dcmp(a.z-b.z)== ;
}
typedef Point3 Vector3;
Vector3 operator+(Vector3 A,Vector3 B){
return Vector3(A.x+B.x,A.y+B.y,A.z+B.z);
}
Vector3 operator-(Vector3 A,Vector3 B){
return Vector3(A.x-B.x,A.y-B.y,A.z-B.z);
}
Vector3 operator*(Vector3 A,double p){
return Vector3(A.x*p,A.y*p,A.z*p);
}
Vector3 operator/(Vector3 A,double p){
return Vector3(A.x/p,A.y/p,A.z/p);
} double Dot(Vector3 A,Vector3 B){return A.x*B.x+A.y*B.y+A.z*B.z;}
double Length(Vector3 A){return sqrt(Dot(A,A));}
double Angle(Vector3 A,Vector3 B){return acos(Dot(A,B)/Length(A)/Length(B));}
//叉积
Vector3 Cross(Vector3 A,Vector3 B){
return Vector3(A.y*B.z-A.z*B.y,A.z*B.x-A.x*B.z,A.x*B.y-A.y*B.x);
}
//点p到射线AB的距离
double DDSXJL(Point3 p,Point3 A,Point3 B){
if(A==B)return Length(p-A);
Vector3 v1=B-A,v2=p-A;
if(dcmp(Dot(v1,v2))<)return Length(v2);
else return Length(Cross(v1,v2))/Length(v1);
}
//******************************************************************************
int main(){
Point3 now[],fut[],delta;
int T;cin>>T; for(int kase=;kase<=T;kase++){ int time;cin>>time;
cin>>now[].x>>now[].y>>now[].z;
cin>>fut[].x>>fut[].y>>fut[].z;
cin>>now[].x>>now[].y>>now[].z;
cin>>fut[].x>>fut[].y>>fut[].z; Point3 B;//坐标原点
delta=now[]-now[];//相对初位置
Vector3 speed=((fut[]-now[])-(fut[]-now[]));//相对速度
printf("Case %d: %.4lf\n",kase,DDSXJL(B,delta,delta+speed));//答案就是原点到轨迹的距离
}return ; }
//*******************************************************************************

[ACM_几何] The Deadly Olympic Returns!!! (空间相对运动之最短距离)的更多相关文章

  1. [ACM_几何] Metal Cutting(POJ1514)半平面割与全排暴力切割方案

    Description In order to build a ship to travel to Eindhoven, The Netherlands, various sheet metal pa ...

  2. [ACM_几何] UVA 11300 Spreading the Wealth [分金币 左右给 最终相等 方程组 中位数]

    Problem A Communist regime is trying to redistribute wealth in a village. They have have decided to ...

  3. [ACM_几何] F. 3D Triangles (三维三角行相交)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28235#problem/A 题目大意:给出三维空间两个三角形三个顶点,判断二者是否有公共 ...

  4. [ACM_几何] Wall

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/E 题目大意:依次给n个点围成的一个城堡,在周围建围墙,要求围墙 ...

  5. [ACM_几何] Pipe

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/B     本题大意: 给定一个管道上边界的拐点,管道宽为1,求 ...

  6. [ACM_几何] Fishnet

      http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/C 本题大意:有一个1X1的矩形,每边按照从小到大的顺序给n ...

  7. [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)

    Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...

  8. [ACM_几何] Transmitters (zoj 1041 ,可旋转半圆内的最多点)

    Description In a wireless network with multiple transmitters sending on the same frequencies, it is ...

  9. postgis几何操作函数集

    管理操作函数 AddGeometryColumn - Adds a geometry column to an existing table of attributes. By default use ...

随机推荐

  1. ibatis 批量插入oracle总结

    1. 使用批量插入最先想到如下的插入语句 insert into a (id,name) values('','') ,('','') 但是 oracle 并不支持这种写法 然后查询得知可以使用如下写 ...

  2. redis五种数据类型的使用(zz)

    redis五种数据类型的使用 redis五种数据类型的使用 (摘自:http://tech.it168.com/a2011/0818/1234/000001234478_all.shtml ) 1.S ...

  3. eclipse如何安装cdt

    原文地址:http://zhidao.baidu.com/link?url=9vSDAkpKJjLIIXP9wFqfjTSf-PmrEr9excDc-A3rzRh46jgzzbud0Z7gzjfxT8 ...

  4. 遍历指定目录下指定类型文件的函数(fatkun Fix版)

    // ================================================================ // 遍历某个文件夹及子文件夹下某种文件, // 使用说明 // ...

  5. APP审核被拒,原因总结

    今天早上,突然看到上周末提交的APP,审核被拒了.原以为是因为IPV6审核没过,后来查看原因后发现是,app的3张展示图里面,有些内容显示的有:测试XX等字眼.苹果说提交的版本不能是含有 test,t ...

  6. 一般多项式曲线的最小二乘回归(Linear Regression)

    对于一般多项式: K为多项式最高项次,a为不确定的常数项,共k+1个; 有离散数据集对应,其方差: β为,方差函数S对β自变量第j个参数的梯度(偏导数): 当以上梯度为零时,S函数值最小,即: 中的每 ...

  7. Oracle表空间数据文件移动的方法

    最近遇到这样的一个问题,Oracle存放表空间文件的盘符 空间不够了,必须把部分表空间迁移出去, [转]http://www.jb51.net/article/77026.htm 实现把用户表空间中的 ...

  8. 32位Windows 7系统下,显示4G内存3G可用的原因。

    由于32位操作系统只有那么多物理地址可用, 而硬盘.光驱.声卡,显卡,无线网卡等硬件设备也需要分配物理地址才可以使用, 所以系统会把一部分物理地址分配给它们, 剩下的物理地址分配给内存使用, 而剩下的 ...

  9. IIS处理并发请求时出现的问题及解决

    一个ASP.NET项目在部署到生产环境时,当用户并发量达到200左右时,IIS出现了明显的请求排队现象,发送的请求都进入等待,无法及时响 应,系统基本处于不可用状态.因经验不足,花了很多时间精力解决这 ...

  10. JavaScript中对象的含义与this的指向

    JavaScript中的对象:无序属性的集合 -其属性可以包含基本值.对象或函数.对象就是一组没有顺序的值.我们可以吧JavaScript中的对象想象成键值对,其中值可以是数据和函数.对象的行为和特征 ...