当前位置:网站首页>Cargo placement problem

Cargo placement problem

2022-07-07 13:57:00 Beauty of algorithm and programming

1. problem

Xiaolan has a huge warehouse , It can hold a lot of goods .

Now? , Xiao Lan has n Boxes of goods should be placed in the warehouse , Every box of goods is a cube of rules . Xiao Lan has set a long 、 wide 、 High three mutually perpendicular directions , The sides of each case must be strictly parallel to the length of the container 、 wide 、 high .

Xiao Lan hopes that all the goods will finally be placed into a big cube . That is in the long 、 wide 、 Stack separately in the high direction L、W、H Of goods , Satisfy n=L*W*H.

for example , When n=4 when , There are the following 6 Kind of plan :1*1*4、1*2*2、1*4*1、2*1*2、2*2*1、4*1*1.

Excuse me, , When n=2021041820210418 when , How many ways are there ?

2. Algorithm description

First write n Value , Then create a list ans, Variable i from 1 Traversing n The number after rounding off the square , If n Yes i The rest is 0, will i and n Yes i Rounding down of integer division is added to ans list , Then record each scheme that meets the conditions in the form of tuples , utilize set() Function de duplication , Use three cycles respectively in ans Take three numbers , If the three numbers are multiplied, they are equal to n, Add these three to set Element set , Finally, the length of the element set is the answer to the question .

3. Experimental results and discussion

Through the experiment 、 Practice has proved that the proposed method is effective , Is able to solve the problem raised at the beginning .

Code list 1

n = 2021041820210418
ans = []
for i in range(1,int(n**0.5)+1):
   if n % i == 0:
       ans.append(i)
       ans.append(n//i)
case = set()
for a in ans:
   for b in ans:
       for c in ans:
           if a * b * c == n:
               case.add((a,b,c))
print(len(case))

4 Conclusion

This article covers built-in set function 、for loop 、if Judgment of conditional statements and tuples , Article “**” It means power ,“//” Is an arithmetic operator , Represents integer division , You can return the integer part of the quotient ( Rounding down ), These knowledge points have been further consolidated , Through the experiment 、 Practice has proved that the proposed method is effective , It is able to solve the problems raised at the beginning .

原网站

版权声明
本文为[Beauty of algorithm and programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071041110274.html