设为首页 加入收藏

TOP

hdu4617 Weapon(立体几何题)
2014-11-23 21:38:17 来源: 作者: 【 】 浏览:8
Tags:hdu4617 Weapon 立体 几何
Weapon
Time Limit: 3000/1000 MS ( Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 279 Accepted Submission(s): 220
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  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
2013 Multi-University Training Contest 2
没啥技巧吧,就是直接算
思路:对于每一个圆柱,算出它的中心轴方向向量同时保存圆心坐标,算出两个直线之间的距离d,如果距离大于两个圆柱的半径之和那就记录mind=d-rr[i]-rr[j],否则就输出Lucky。两直线平行时距离好算,不平行时有点麻烦,用向量的叉乘来计算。
#include  
#include  
double r[31][3],center[31][3],rr[31];  
  
int main()  
{  
    double x1,x2,x3,y1,y2,y3,z1,z2,z3,r1,r2,r3,mind,temp,temp1;  
    double a1,b1,c1,a2,b2,c2;  
    int t,n,m,i,j,k,flag;  
    scanf("%d",&t);  
    while(t--)  
    {  
        scanf("%d",&n);  
        for(i=0;itemp-(rr[i]+rr[j]))  
                        mind=temp-rr[i]-rr[j];  
                    //printf("%.2f\n",temp);  
                }  
                else //平行  
                {  
                    a2=center[i][0]-center[j][0],b2=center[i][1]-center[j][1],c2=center[i][2]-center[j][2];  
                    temp1=sqrt(((b1*c2-b2*c1)*(b1*c2-b2*c1)+(a2*c1-a1*c2)*(a2*c1-a1*c2)+(a1*b2-b1*a2)*(a1*b2-b1*a2))/(a1*a1+b1*b1+c1*c1));  
                    if(temp1<=rr[i]+rr[j])  
                    {  
                        printf("Lucky\n");  
                        flag=0;  
                        break;  
                    }  
                    else if(mind>temp1-rr[i]-rr[j])  
                        mind=temp1-rr[i]-rr[j];  
                }  
            }  
        }  
        if(flag)  
            printf("%.2f\n",mind);  
    }  
    return 0;  
}  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇串的模式匹配 下一篇UVA 111 History Grading(dp + LC..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)
·使用华为开发者空间 (2025-12-27 04:19:24)
·Getting Started wit (2025-12-27 03:49:24)
·Ubuntu 上最好用的中 (2025-12-27 03:49:20)