hdu 4617 Weapon 计算异面直线间距离

Weapon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 321    Accepted Submission(s): 257


Problem Description
  Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a circle. When it fires, rays form a cylinder that runs through the circle verticality in both side. If one cylinder of rays touch another, there will be an horrific explosion. Originally, all circles can rotate easily. But for some unknown reasons they can not rotate any more. If these weapon can also make an explosion, then Doctor D. is lucky that he can also test the power of the weapon. If not, he would try to make an explosion by other means. One way is to find a medium to connect two cylinder. But he need to know the minimum length of medium he will prepare. When the medium connect the surface of the two cylinder, it may make an explosion.
 

Input
  The first line contains an integer T, indicating the number of testcases. For each testcase, the first line contains one integer N(1 < N < 30), the number of weapons. Each of the next 3N lines&#160; contains three float numbers. Every 3 lines represent one weapon. The first line represents the coordinates of center of the circle, and the second line and the third line represent two points in the circle which surrounds the center. It is supposed that these three points are not in one straight line. All float numbers are between -1000000 to 1000000.
 

Output
  For each testcase, if there are two cylinder can touch each other, then output 'Lucky', otherwise output then minimum distance of any two cylinders, rounded to two decimals, where distance of two cylinders is the minimum distance of any two point in the surface of two cylinders.
 

Sample Input
  
  
3 3 0 0 0 1 0 0 0 0 1 5 2 2 5 3 2 5 2 3 10 22 -2 11 22 -1 11 22 -3 3 0 0 0 1 0 1.5 1 0 -1.5 112 115 109 114 112 110 109 114 111 -110 -121 -130 -115 -129 -140 -104 -114 -119.801961 3 0 0 0 1 0 1.5 1 0 -1.5 112 115 109 114 112 110 109 114 111 -110 -121 -130 -120 -137 -150 -98 -107 -109.603922
 

Sample Output
  
  
Lucky 2.32 Lucky
 

Source
 

Recommend
zhuyuanchen520
 



#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;

const double eps = 1e-6;
const int INF=0xfffff;

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

struct point{
    double x,y,z;
};

struct plane{
    point a,b,c;
    point d;
    double r;
}vis[33];


point operator - (point A,point B)
{
    A.x-=B.x;
    A.y-=B.y;
    A.z-=B.z;
    return A;
}

point operator ^ (point A,point B)
{
    point C;
    C.x=A.y*B.z-A.z*B.y;
    C.y=A.z*B.x-A.x*B.z;
    C.z=A.x*B.y-A.y*B.x;
    return C;
}

double operator * (point A,point B)
{
    return A.x*B.x+A.y*B.y+A.z*B.z;
}

point xmult(point u,point v)
{
    point ret;
    ret.x=u.y*v.z-u.z*v.y;
    ret.y=u.z*v.x-u.x*v.z;
    ret.z=u.x*v.y-u.y*v.x;
    return ret;
}

double dmult(point u,point v)
{
    return u.x*v.x+u.y*v.y+u.z*v.z;
}

point subt(point u,point v)
{
    point ret;
    ret.x=u.x-v.x;
    ret.y=u.y-v.y;
    ret.z=u.z-v.z;
    return ret;
}

double vlen(point p)
{
    return sqrt(p.x*p.x+p.y*p.y+p.z*p.z);
}

double juli(point A,point B)
{
    double r;
    r=sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)+(A.z-B.z)*(A.z-B.z));
    return r;
}

double linetoline(plane A,plane B)
{
    point N=A.d^B.d;
    double l=fabs(N*(A.a-B.a))/sqrt(N*N);
    return l-A.r-B.r;
}


int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,i,j;
        double ans;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%lf%lf%lf",&vis[i].a.x,&vis[i].a.y,&vis[i].a.z);
            scanf("%lf%lf%lf",&vis[i].b.x,&vis[i].b.y,&vis[i].b.z);
            scanf("%lf%lf%lf",&vis[i].c.x,&vis[i].c.y,&vis[i].c.z);
            vis[i].r=juli(vis[i].a,vis[i].b);
            vis[i].d=(vis[i].b-vis[i].a)^(vis[i].c-vis[i].a);
        }
        ans=INF;
        for(i=0;i<n;i++)
        {
            for(j=i+1;j<n;j++)
            {
                ans=min(ans,linetoline(vis[i],vis[j]));
                //cout<<ans<<endl;
            }
        }
        if(dcmp(ans)<=0)
            cout<<"Lucky\n";
        else
            printf("%.2lf\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值