当前位置:网站首页>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
- Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
- Is the compass stock software reliable? Is it safe to trade stocks?
- Lavarel之环境配置 .env
- ES日志报错赏析-Limit of total fields
- 最佳实践 | 用腾讯云AI意愿核身为电话合规保驾护航
- Laravel form builder uses
- 2022-7-6 Leetcode 977.有序数组的平方
- Flink | multi stream conversion
- 内存溢出和内存泄漏的区别
猜你喜欢
室内ROS机器人导航调试记录(膨胀半径的选取经验)
C语言数组相关问题深度理解
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
Flink | multi stream conversion
Evolution of customer service hotline of dewu
2022-7-7 Leetcode 844. Compare strings with backspace
MySQL error 28 and solution
Take you to master the three-tier architecture (recommended Collection)
2022-7-6 beginner redis (I) download, install and run redis under Linux
Redis can only cache? Too out!
随机推荐
2022-7-6 beginner redis (I) download, install and run redis under Linux
Problems that cannot be accessed in MySQL LAN
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
[1] Basic knowledge of ros2 - summary version of operation commands
Mysql怎样控制replace替换的次数?
Laravel form builder uses
Toraw and markraw
带你掌握三层架构(建议收藏)
FCOS3D label assignment
PHP - laravel cache
2022-7-6 Leetcode 977. Square of ordered array
Getting started with MySQL
Redis can only cache? Too out!
How to check the ram and ROM usage of MCU through Keil
Excerpt from "misogyny: female disgust in Japan"
【堡垒机】云堡垒机和普通堡垒机的区别是什么?
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
【日常训练--腾讯精选50】231. 2 的幂
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis