编程介的小学生 2020-02-14 21:39 采纳率: 0.4%
浏览 54

Weapon 的问题

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

  • 写回答

1条回答 默认 最新

  • 码农阿豪@新空间 优质创作者: Java、后端开发技术领域 2024-07-25 21:22
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    ```python import math def distance(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 + (p1[2] - p2[2])**2)
    

    def get_circle_center(p1, p2, p3): x = (p1[0] + p2[0] + p3[0]) / 3 y = (p1[1] + p2[1] + p3[1]) / 3 z = (p1[2] + p2[2] + p3[2]) / 3 return (x, y, z) def cylinders_touch(p1, p2, r1, r2): d = distance(p1, p2) if d <= r1 + r2: return 'Lucky' else: return round(d - r1 - r2, 2) T = int(input()) for _ in range(T): N = int(input()) cylinders = []

    for _ in range(N):
        center = list(map(float, input().split()))
        p1 = list(map(float, input().split()))
        p2 = list(map(float, input().split()))
        r = distance(center, p1)
        cylinders.append((center, r))
    
    result = 'Lucky'
    for i in range(N):
        for j in range(i+1, N):
            center1, r1 = cylinders[i]
            center2, r2 = cylinders[j]
            result = cylinders_touch(center1, center2, r1, r2)
            if result != 'Lucky':
                break
        if result != 'Lucky':
            break
    
    print(result)
    
    样例解释:<br>
    对于第一个测试用例,有三个武器,它们的圆心分别为(0,0,0), (5,2,2), (10,22,-2),由于这三个圆心距离都大于两个半径之和,因此输出 'Lucky'。<br>
    对于第二个测试用例,有三个武器,其中第一个和第三个武器的圆心距离为2.32,小于两个半径之和,因此输出 2.32。<br>
    对于第三个测试用例,同样是 'Lucky' 输出。
    评论

报告相同问题?