hdu 4617 Weapon (几何)

本文深入探讨了D博士发明的恐怖武器的威力测试过程,特别是两个圆柱相交并相切的条件对测试的重要性。通过解析圆柱间距离计算和相交判断,揭示了武器测试的可能性及替代爆炸方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
 

   题意是:D博士发明了一个新武器,要对它进行威力测试。可以威力测试的条件是圆形炮筒两端发出的射线构成无限长的圆柱,若有两个圆柱相交后相切,则可以测试,输出“Lucky”否则输出圆柱间的最短距离。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
struct point
{
    double x,y,z;
    double a,b,c;
    double r;
}node[45];
double solve(point p1,point p2)
  {
      double a1,a2,b1,b2,c1,c2;
      double s1,s2,s3;
      double q1,q2,q3;
      double ans1,ans2,ans3;
      a1=p1.x,b1=p1.y,c1=p1.z;
      a2=p2.x,b2=p2.y,c2=p2.z;
      s1=b1*c2-b2*c1;
      s2=c1*a2-c2*a1;
      s3=a1*b2-a2*b1;
      q1=p2.a-p1.a;
      q2=p2.b-p1.b;
      q3=p2.c-p1.c;
      ans1=fabs(q1*s1+q2*s2+q3*s3);
      ans2=sqrt(s1*s1+s2*s2+s3*s3);
      ans3=ans1/ans2;
    return ans3;
  }

int main()
{
   int t,n,i,j;
   double x1,x2,x3,y1,y2,y3,z1,z2,z3;
   double a1,a2,b1,b2,c1,c2;
  scanf("%d",&t);
  while(t--)
  {
      scanf("%d",&n);
     for(i=0;i<n;i++)
      {
        cin>>x1>>y1>>z1>>x2>>y2>>z2>>x3>>y3>>z3;
         node[i].a=x1;node[i].b=y1;node[i].c=z1,
         a1=x2-x1;b1=y2-y1;c1=z2-z1;
         a2=x3-x1;b2=y3-y1;c2=z3-z1;
         node[i].r=sqrt(a1*a1+b1*b1+c1*c1);
         node[i].x=b1*c2-b2*c1;
         node[i].y=c1*a2-c2*a1;
         node[i].z=a1*b2-a2*b1;
      }
   bool flag=false;
   double ss=1e8;
   double tmp;
  for(i=0;i<n;i++)
  {
      for(j=i+1;j<n;j++)
      {
             tmp=solve(node[i],node[j]);
             tmp=tmp-node[i].r-node[j].r;
                if(tmp<=0)
                {
                    flag=true;
                    break;
                }
                if(tmp<ss)
                  ss=tmp;
      }
    if(flag) break;
  }
   if(flag)
      printf("Lucky\n");
   else
     printf("%.2lf\n",ss);
  }

   return 0;
    }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值