# UVa 10794 - The Deadly Olympic Returns!!!

1. 本题一个较好的做法是相对运动 ， 即假设一个物体静止 ， 然而另一个物体沿着某一个速度运动(两个运动的速度的差,,,这里不准确 ， 毋喷)

2. 然后就是一个线段和点距离的裸题目了

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
const double eps = 1e-8;

inline int dcmp (double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; }

struct points
{
double x , y , z;
points(double x =0 , double y =0  , double z = 0):x(x),y(y),z(z){}
};

typedef points Vector;

Vector operator +(Vector a , Vector b) { return Vector(a.x+b.x , a.y+b.y , a.z+b.z); }
Vector operator -(Vector a , Vector b) { return Vector(a.x-b.x , a.y-b.y , a.z-b.z); }
Vector operator *(Vector a , double b) { return Vector(a.x*b   , a.y*b   , a.z*b  ); }
Vector operator /(Vector a , double b) { return Vector(a.x/b   , a.y/b   , a.z/b  ); }
bool operator ==(Vector a , Vector b) { return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0 && dcmp(a.z-b.z)==0; }

double Dot(Vector a , Vector b) { return a.x*b.x+a.y*b.y+a.z*b.z; }
Vector Cross(Vector a , Vector b) { return Vector(a.y*b.z-a.z*b.y , a.z*b.x-a.x*b.z , a.x*b.y-a.y*b.x); }
double Length(Vector a) { return sqrt(Dot(a, a)); }

double DistanceOfPointsAndSegment(points p , points a , points b)
{
if(a==b) return Length(p-a);
Vector v1 = b-a , v2 = p-a , v3= p-b;
if(dcmp(Dot(v1, v2))<0) return Length(v2);
if(dcmp(Dot(v1, v3))>0) return Length(v3);
return Length(Cross(v1, v2))/Length(v1);
}

int main(int argc, char *argv[]) {

int t;
scanf("%d",&t);

for(int Case=1;Case<=t;Case++)
{
double times ;
scanf("%lf",×);
points a , b , c , d;
Vector u = (b-a)/times , v = (d-c)/times;

printf("Case %d: %.4lf\n",Case,DistanceOfPointsAndSegment(a , c , c+(v-u)*(1e10)));
}

return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：UVa 10794 - The Deadly Olympic Returns!!! 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)