当前位置:网站首页>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 .
边栏推荐
- 高等数学---第八章多元函数微分学1
- "New red flag Cup" desktop application creativity competition 2022
- postgresql array类型,每一项拼接
- [fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
- 566. Reshaping the matrix
- Leetcode simple question sharing (20)
- AI talent cultivation new ideas, this live broadcast has what you care about
- 社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
- Realization of search box effect [daily question]
- 2022-7-6 Leetcode27.移除元素——太久没有做题了,为双指针如此狼狈的一天
猜你喜欢
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
10 pictures open the door of CPU cache consistency
Sliding rail stepping motor commissioning (national ocean vehicle competition) (STM32 master control)
Redis 核心数据结构 & Redis 6 新特性详
Getting started with MySQL
SSRF vulnerability file pseudo protocol [netding Cup 2018] fakebook1
带你掌握三层架构(建议收藏)
室内ROS机器人导航调试记录(膨胀半径的选取经验)
Redis只能做缓存?太out了!
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
随机推荐
为租客提供帮助
[daily training -- Tencent select 50] 231 Power of 2
LeetCode_ Binary search_ Medium_ 153. Find the minimum value in the rotation sort array
Did login metamask
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Help tenants
Realize the IP address home display function and number home query
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
手里的闲钱是炒股票还是买理财产品好?
Learning breakout 2 - about effective learning methods
Toraw and markraw
高等数学---第八章多元函数微分学1
2022-7-7 Leetcode 844.比较含退格的字符串
648. Word replacement: the classic application of dictionary tree
使用day.js让时间 (显示为几分钟前 几小时前 几天前 几个月前 )
flask session伪造之hctf admin
.net core 关于redis的pipeline以及事务
Redis只能做缓存?太out了!
室内ROS机器人导航调试记录(膨胀半径的选取经验)
Error lnk2019: unresolved external symbol