欧拉计划 发表于 2017-1-5 16:05:18

题目222:球的包装

Sphere Packing

What is the length of the shortest pipe, of internal radius 50mm, that can fully contain 21 balls of radii 30mm, 31mm, ..., 50mm?

Give your answer in micrometres (10-6 m) rounded to the nearest integer.

题目:

一个管子内部半径 50mm,如果要完全容纳 21 个半径分别为 30mm, 31mm, ..., 50mm 的球,那么这个管子的最短长度为多少?

格式要求:以微米(10-6 m)为单位的最接近实际值的整数。


pikaso 发表于 2018-3-21 00:48:21

{:10_266:}不知道怎么上传图片
public class lglr {
        public static void main(String[] args) {
                double sum = 0;
                double temp = 0;
                for(double i = 30.0;i < 50;i++) {
                        sum += i;
                        temp = len(i,i+1);
                }
                System.out.println(sum+50-temp);
        }
        public static double len(double r1,double r2) {
                return r1+r2-Math.sqrt((Math.pow((r1+r2),2)-Math.pow(50-(r1+r2),2)));
        }
}
{:10_266:}第一次写,哪个大佬指正一下哈

doodu 发表于 2019-6-17 22:38:24

本帖最后由 doodu 于 2019-6-18 08:13 编辑

不会弄图片{:5_100:},如果错了请指正

from math import sqrt#使用数学计算库中的开方函数

def ball_n():
        width = 50.0*2   #说明管子的直径是100mm,加入.0变为浮点数
        r = 50.0         #放入第一个小球,第一个小球的半径为50mm,
                         #直径与管子内部直径一致
        temp = 0.0       #声明管子最小长度的变量为0,方便之后累加
        while 1:
                temp += sqrt((width-r-(r-1))**2+(r+(r-1))**2) #见不了草图
                r -= 1       #半径递减
                if r <= 30:#因为当前循环半径变量使用第n-1个小球,
                           #经过第10行做半径递减后,加入判断语句防止越界
                        break
        h_max = temp + width/2 + r/2#见不了草图
        return int(h_max*(10**3))   #返回值单位毫米,折算微米需要下降3个数量级

print(ball_n( ))


我计算的答案是:1738074微米
页: [1]
查看完整版本: 题目222:球的包装