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. C# 反转字符串方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 反转字符 ...

  2. racle wm_concat(column)函数的使用

    oracle wm_concat(column)函数使我们经常会使用到的,下面就教您如何使用oracle wm_concat(column)函数实现字段合并,如果您对oracle wm_concat( ...

  3. crack.vbs病毒,优盘里所有文件全变成快捷方式

    去了一趟学校打印店,用优盘copy打印了点东西,当时在打印店电脑里打开优盘的时候里面就变成了快捷方式,但没怎么在意.回来之后在自己电脑上居然也这样了.网上一搜是中了crack.vbs病毒了.格式化优盘 ...

  4. UI基础之UIButton相关

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 1.按钮透明效果 btn.alpha = 0.8; 2.按钮圆角处理 btn ...

  5. JavaScript常用方法100种

    1.输出语句:document.write(""); 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...

  6. PHP使用XHProf进行性能分析

    1. 编译安装 wget http://pecl.php.net/get/xhprof-0.9.3.tgz tar zxvf xhprof-0.9.3.tgz cd xhprof-0.9.3/exte ...

  7. 我与solr(三)--solr后台相关介绍

    1.DashBoard: 介绍了当前solr的相关信息,运行时间,版本信息,java虚拟机的配置信息. 注意我们的solr与lucence的版本号是保持一致的,而不同的lucence版本也需要对应的j ...

  8. 我与solr(二)--导入mysql数据库

    关于solr的搭建详见上一篇的随笔. 步骤1: 在webapps中solrhome下新建一个文件夹名字叫做mynode(名字不固定,可以随便取,但是这个名字在后面的配置中会有所关联.)然后在mynod ...

  9. Java读取文件的几种方式

    package com.mesopotamia.test; import java.io.BufferedReader; import java.io.ByteArrayInputStream; im ...

  10. reduce方法

    API里面这样写 reduce(initial, sym) → obj                              reduce(初始值,符号) reduce(sym) → obj re ...