当前位置:网站首页>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 .
边栏推荐
- PHP - laravel cache
- The meaning of variables starting with underscores in PHP
- Custom thread pool rejection policy
- Realize the IP address home display function and number home query
- move base参数解析及经验总结
- SSRF漏洞file伪协议之[网鼎杯 2018]Fakebook1
- AI talent cultivation new ideas, this live broadcast has what you care about
- Use day JS let time (displayed as minutes, hours, days, months, and so on)
- 2022-7-6 Leetcode 977. Square of ordered array
- MySQL error 28 and solution
猜你喜欢
得物客服热线的演进之路
Final review notes of single chip microcomputer principle
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
带你掌握三层架构(建议收藏)
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
DID登陆-MetaMask
作战图鉴:12大场景详述容器安全建设要求
Redis can only cache? Too out!
Deep understanding of array related problems in C language
How to make join run faster?
随机推荐
【堡垒机】云堡垒机和普通堡垒机的区别是什么?
PHP - laravel cache
Navicat运行sql文件导入数据不全或导入失败
高等数学---第八章多元函数微分学1
How to make join run faster?
Getting started with MySQL
内存溢出和内存泄漏的区别
作战图鉴:12大场景详述容器安全建设要求
Use of polarscatter function in MATLAB
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
供应链供需预估-[时间序列]
Ogre introduction
Oracle advanced (V) schema solution
Flask session forged hctf admin
Navicat run SQL file import data incomplete or import failed
Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
Dry goods | summarize the linkage use of those vulnerability tools
2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
Show the mathematical formula in El table
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)