宝山青岛网站建设,关于营销的最新的新闻,php做网站有哪些优点,设计资料网站工厂有若干条生产线#xff0c;可以生产不同型号的产品#xff0c;要求实现功能如下#xff1a;1. ProductionLineMgmtSys 初始化生产线和产品的生产周期有num条生产线#xff0c;编号从0开始periods[i]表示生产一个型号为i的产品所需的生产周期#xff0c;单位为天2. Pro… 工厂有若干条生产线可以生产不同型号的产品要求实现功能如下1. ProductionLineMgmtSys 初始化生产线和产品的生产周期有num条生产线编号从0开始periods[i]表示生产一个型号为i的产品所需的生产周期单位为天2. Produce 在生产线assemblyId上从日期date开始持续生产型号productId的产品若生产线空闲开始生产并返回1若生产线正在生产该型号产品则命令忽略返回0若正在生产其他型号立刻切换返回-1产品完成日期若某生产线在date开始生产某型号产品生产周期为period则日期dateN*period均为「产品完成日期」假设date为2period为3则完成日期为5、8、11...生产切换规则若非在产品完成日期发生切换则正在生产的产品未完成废弃不计若在产品完成日期发生切换则计数并同时启动下一产品的生产。3. GetProductCount 查询截止date含累计完成型号productId的产品数量。生产完成即 产品完成日期date
输入输出样例
[ProductionLineMgmtSys,produce,getProductCount,getProductCount]
[[2,[1,3]],[0,1,1],[8,1],[9,1]]
[null,1,2,3][ProductionLineMgmtSys,produce,produce,getProductCount,produce,produce,getProductCount,produce,produce,produce,getProductCount,produce]
[[5,[1,4,5,8,2,3]],[0,1,0],[1,1,5],[4,0],[5,0,5],[7,0,0],[7,5],[8,1,5],[8,4,0],[9,1,0],[10,0],[1000,4,0]]
[null,1,-1,1,1,-1,2,0,1,-1,7,0]题给代码
class ProductionLineMgmtSys {public:ProductionLineMgmtSys(int num, const vectorint periods){}int Produce(int date, int assemblyId, int productId){}int GetProductCount(int date, int productId){}
};from typing import List
import copyclass ProductionLineMgmtSys:def __init__(self, num: int, periods: List[int]):
self.produc_line dict.fromkeys(range(num)) #key:生产线id value:生产产品id
self.produc_number dict.fromkeys(range(len(periods)), 0) #key:产品id value:生产数量
self.produc_line_product_start_date dict.fromkeys(range(num)) #key:生产线id value:生产产品开始时间
self.periods periodsdef produce(self, date: int, assembly_id: int, product_id: int) - int:
if self.produc_line[assembly_id] None:
self.produc_line[assembly_id] product_id
self.produc_line_product_start_date[assembly_id] date
return 1
elif self.produc_line[assembly_id] product_id:
return 0
else:
i 0
while(self.produc_line_product_start_date[assembly_id] i * self.periods[self.produc_line[assembly_id]] date):
i 1
self.produc_number[self.produc_line[assembly_id]] i - 1
self.produc_line_product_start_date[assembly_id] date
self.produc_line[assembly_id] product_id
return -1def get_product_count(self, date: int, product_id: int) - int:
product_achive_number 0
if product_id in self.produc_line.values():
product_id_in_produc_line [i for i,x in enumerate(self.produc_line.values()) if x product_id]
#该生产线还在生产对应产品
produc_number1 copy.deepcopy(self.produc_number)
for assembly_id1 in product_id_in_produc_line:
i 0
while(self.produc_line_product_start_date[assembly_id1] i * self.periods[product_id] date):
i 1
produc_number1[product_id] copy.deepcopy(i - 1)
product_achive_number copy.deepcopy(produc_number1[product_id])
else:
product_achive_number copy.deepcopy(self.produc_number[product_id])
return product_achive_numberif __name__ __main__:# ms ProductionLineMgmtSys(2,[1,3])
# p ms.produce(0,1,1)
# g ms.get_product_count(8,1)
# g1 ms.get_product_count(9,1)
#[ProductionLineMgmtSys,produce,produce,getProductCount,produce,produce,getProductCount,produce,produce,produce,getProductCount,produce]
#
#[[5,[1,4,5,8,2,3]],[0,1,0],[1,1,5],[4,0],[5,0,5],[7,0,0],[7,5],[8,1,5],[8,4,0],[9,1,0],[10,0],[1000,4,0]]ms ProductionLineMgmtSys(5,[1,4,5,8,2,3])
p1 ms.produce(0,1,0)
p2 ms.produce(1,1,5)
g3 ms.get_product_count(4,0)
p4 ms.produce(5,0,5)
p5 ms.produce(7,0,0)
g6 ms.get_product_count(7,5)
p7 ms.produce(8,1,5)
p8 ms.produce(8,4,0)
p9 ms.produce(9,1,0)
g10 ms.get_product_count(10,0)
p11 ms.produce(1000,4,0)
s 2某工厂使用激光刀切割材料。激光刀具有开启和关闭两种状态并可转向和移动。支持指令如下
O —— 开启激光刀即 “OPEN”指令执行后激光刀处于开启状态
C —— 关闭激光刀即 “CLOSE”指令执行后激光刀处于关闭状态
M —— 激光刀沿着当前方向前进一段距离即 “MOV”)若激光刀在开启状态下会同步进行材料切割否则只移动不切割
UDLR —— 改变激光刀的前进方向、但不移动上U下D左L右R
给定一块高为 height宽为 width 的材料。初始时激光刀位于材料左上角处于关闭状态前进方向为朝下 (D)。
激光刀的操作指令依次记录于字符串 operations所有 M 指令的移动距离依次记录于数组 distancesdistances[i] 表示第 i 个 M 指令的移动距离。
请计算完成操作指令后材料板上被切割出了多少个 1 x 1 的方块。
注意输入数据保证激光刀始终在材料初始范围内可在材料边上即激光刀的位置 [row, col] 始终满足 0 row height0 col width。
示例 1
输入 height 3 width 4 operations “MRMOMDMLMUMCRMODMC” distances [1,1,2,1,2,2,1,2]
输出3
解释operations 中有 8 个 M对应的移动距离在数组distances中。 如图所示激光刀移动的位置顺序 0-1-2-3-…-8 。其中黄色的线是激光刀开启情形下切割的路径。这样最终图中的 3 个阴影位置是切割所得的 1 x 1 方块。 示例 2
输入 height 3 width 4 operations “MRMOMDMLMUMC” distances [1,1,2,1,2,2]
输出0
解释如图所示没有切割出 1 x 1 的方块故返回 0。 注意下图中切出的是一个 2 x 1 的材料块不是两个 1 x 1 的方块。 示例 3
输入 height 3 width 3 operations “MROMDMLMUMRMDMRMUMLMC” distances [1,2,1,2,1,1,1,1,1,1]
输出2
提示
1 height, width 100 0 operations.length 10^4 distances.length 等于 operations 中 M 的个数 operations[i] 仅为 ‘O’、‘C’、‘U’、‘D’、‘L’、‘R’、‘M’ 一条边可能会被多次切割
解题思路 判断格子的四条边是否被切割过, 一共有水平边w * (h 1) ,垂直边 h * (w 1)
from typing import Listclass Solution:def __init__(self):self.block_num 0self.line_h []self.line_v []def init_block(self, height, width):self.line_h [[0 for _ in range(width)] for _ in range(height 1)]self.line_v [[0 for _ in range(height)] for _ in range(width 1)]for x in range(0, width):self.line_h[0][x] 1self.line_h[height][x] 1for y in range(0, height):self.line_v[0][y] 1self.line_v[width][y] 1def mv_knife(self, height: int, width: int, operations: str, distances: List[int]):knife_status Cmove_command Dcommand_count -1cur_x 0cur_y 0for command in list(operations):if command O or command C:knife_status commandcontinueelif command M:command_count 1else:move_command commandcontinueif move_command U:next_y cur_y - distances[command_count]if knife_status O:for position in range(next_y, cur_y):self.line_v[cur_x][position] 1cur_y next_yelif move_command D:next_y cur_y distances[command_count]if knife_status O:for position in range(cur_y, next_y):self.line_v[cur_x][position] 1cur_y next_yelif move_command L:next_x cur_x - distances[command_count]if knife_status O:for position in range(next_x, cur_x):self.line_h[cur_y][position] 1cur_x next_xelif move_command R:next_x cur_x distances[command_count]if knife_status O:for position in range(cur_x, next_x):self.line_h[cur_y][position] 1cur_x next_xdef get_block_num(self, height, width):for x in range(0, width):for y in range(0, height):if self.line_h[y][x] and self.line_h[y 1][x] and self.line_v[x][y] and self.line_v[x 1][y]:self.block_num 1return self.block_numdef get_unit_block_num(self, height: int, width: int, operations: str, distances: List[int]) - int:self.init_block(height, width)self.mv_knife(height, width, operations, distances)self.get_block_num(height, width)return self.block_numheight 3
width 4
operations MRMOMDMLMUMCRMODMC
distances [1, 1, 2, 1, 2, 2, 1, 2]ss Solution()
print(ss.get_unit_block_num(height, width, operations, distances))