资源简介
2018华为软件挑战赛赛题中装箱部分的解答代码,可以作为尺寸成倍数关系的一维装箱问题解决方式的参考
代码片段和文件信息
# coding=utf-8
table_1 = {“cpu_16“: [3 0 “flavor13“]
“cpu_8“: [3 0 “flavor10“]
“cpu_4“: [17 0 “flavor7“]
“cpu_2“: [9 0 “flavor4“]
“cpu_1“: [25 0 “flavor1“]}
table_2 = {“cpu_16“: [0 0 “flavor14“]
“cpu_8“: [0 0 “flavor11“]
“cpu_4“: [0 0 “flavor8“]
“cpu_2“: [0 0 “flavor5“]
“cpu_1“: [0 0 “flavor2“]}
table_4 = {“cpu_16“: [0 0 “flavor15“]
“cpu_8“: [0 0 “flavor12“]
“cpu_4“: [0 0 “flavor9“]
“cpu_2“: [0 0 “flavor6“]
“cpu_1“: [0 0 “flavor3“]}
cpu16s = [] #存放所有cpu规格为16的虚拟机,以flavor15,flavor14,flavor13区分
flavors = {“flavor1“: [1 1]
“flavor2“: [1 2]
“flavor3“: [1 4]
“flavor4“: [2 2]
“flavor5“: [2 4]
“flavor6“: [2 8]
“flavor7“: [4 4]
“flavor8“: [4 8]
“flavor9“: [4 16]
“flavor10“: [8 8]
“flavor11“: [8 16]
“flavor12“: [8 32]
“flavor13“: [16 16]
“flavor14“: [16 32]
“flavor15“: [16 64]}
keys = (“cpu_1“ “cpu_2“ “cpu_4“ “cpu_8“ “cpu_16“)
f_keys = (“flavor1“ “flavor2“ “flavor3“ “flavor4“ “flavor5“
“flavor6“ “flavor7“ “flavor8“ “flavor9“ “flavor10“
“flavor11“ “flavor12“ “flavor13“ “flavor14“ “flavor15“)
def fill_table(table):
‘‘‘
将预测数据填装至able_1table_2table_3三个表中
:param table: 预测数据
:return:
‘‘‘
i=0;
while i<15:
if i%3==0:
table_1[keys[i//3]][0] = table.get(f_keys[i])
else:
if i%3==1:
table_2[keys[i // 3]][0] = table.get(f_keys[i])
else:
table_4[keys[i // 3]][0] = table.get(f_keys[i])
i+=1
return
def adapt_table(table):
‘‘‘
归置数据,计算出表中每种CPU规格的虚拟数量
:param table: 所需操作的表,table_1table_2table_3三个中之一
:return:返回值为该表中cpu规格16的个数,包括实际数量和虚拟数量
‘‘‘
i=0
while i<4:
# print(dict.get(keys[i])[0])
table.get(keys[i+1])[1] = (table.get(keys[i])[0]+table.get(keys[i])[1])//2
i+=1
return table.get(keys[4])[0]+table.get(keys[4])[1]
def packaging(tablekeydelnumpackage):
‘‘‘
将对应表中,对应cpu规格的虚拟机,减去对应的数目并将其按照约定填装到箱子中
:param table: 所需操作的表,table_1table_2table_3三个中之一
:param key: 所需操作的物品,表中对应CPU规格,可选cpu_16到dpu_1
:param delnum: 所需减去的个数
:param package: 填装物品的箱子
:return: 所需对应cpu的虚拟数量
‘‘‘
virnum=delnum-(table.get(key)[0])
flavor = table.get(key)[2]
if virnum<=0:
virnum = 0
table.get(key)[0]-=delnum
if flavor in package:
package[flavor]+=delnum
else:
package[flavor]=delnum
else:
if table.get(key)[0]>0 and(flavor in package):
package[flavor]+=table.get(key)[0]
elif table.get(key)[0]>0 :
package[flavor]=table.get(key)[0]
table.get(key)[0] = 0
table.get(key)[1] -= virnum
ret
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论