首页 > 其他分享 >4.4(学号:3025)

4.4(学号:3025)

时间:2024-10-27 21:20:36浏览次数:3  
标签:4.4 profit MAX 3025 hours products max total

MAX_A = 15
MAX_B = 24
MAX_DEBUG = 5

products = [
{"name": "Ⅰ", "A_hours": 1, "B_hours": 6, "debug_hours": 1, "profit": 2}, # 假设产品Ⅰ至少使用1小时设备A
{"name": "Ⅱ", "A_hours": 5, "B_hours": 2, "debug_hours": 1, "profit": 1}
]

max_profit = 0
best_plan = {}

for i in range(MAX_A // products[0]["A_hours"] + 1):
for j in range(MAX_B // products[1]["B_hours"] + 1):
# 计算调试时间是否足够
if (i + j) * max(products[0]["debug_hours"], products[1]["debug_hours"]) > MAX_DEBUG:
continue

    total_A_hours = i * products[0]["A_hours"] + j * products[1]["A_hours"]  
    total_B_hours = i * products[0]["B_hours"] + j * products[1]["B_hours"]  


    if total_A_hours > MAX_A or total_B_hours > MAX_B:  
        continue  


    total_profit = i * products[0]["profit"] + j * products[1]["profit"]  


    if total_profit > max_profit:  
        max_profit = total_profit  
        best_plan = {"Ⅰ": i, "Ⅱ": j}  

print(f"最优生产计划:产品Ⅰ生产{best_plan['Ⅰ']}件,产品Ⅱ生产{best_plan['Ⅱ']}件")
print(f"最大利润为:{max_profit}元")

print("学号:3025")

标签:4.4,profit,MAX,3025,hours,products,max,total
From: https://www.cnblogs.com/tjs200461/p/18509012

相关文章

  • 2.8(学号:3025)
    importnumpyasnp初始化系数矩阵A和常数项向量bn=1000A=np.zeros((n,n))b=np.arange(1,n+1)填充系数矩阵Aforiinrange(n):A[i,i]=4#对角线元素为4ifi<n-1:A[i,i+1]=1#每一行的下一个元素为1ifi>0:A[i,i-1]=1#每一行的上一个元素......
  • 2.9(学号:3025)
    importsympyassp定义变量x,y=sp.symbols('xy')定义方程组equation1=sp.Eq(x**2-y-x,3)equation2=sp.Eq(x+3*y,2)解方程组solutions=sp.solve((equation1,equation2),(x,y),dict=True)print("符号解:")forsolinsolutions:print(sol)......
  • 2.10(学号:3025)
    fromscipy.integrateimportquadimportnumpyasnp第一部分:抛物线旋转体(修正后)defV1_quad(y):returnnp.pi*(4*y-y**2)V1_corrected,_=quad(V1_quad,1,3)第二部分保持不变V2=0.5*(4/3)*np.pi*23-(1/3)*np.pi*22*1计算总体积total_volume_co......
  • 2.12(学号:3025)
    importnumpyasnpfromscipy.linalgimporteig定义矩阵A=np.array([[-1,1,0],[-4,3,0],[1,0,2]])计算特征值和特征向量eigenvalues,eigenvectors=eig(A)打印特征值print("特征值:")print(eigenvalues)打印特征向量print("特征向量:")foriinrange(ei......
  • 2.11(学号:3025)
    importnumpyasnpdeff(x):return(abs(x+1)-abs(x-1))/2+np.sin(x)defg(x):return(abs(x+3)-abs(x-3))/2+np.cos(x)fromscipy.optimizeimportfsolvedefequation_system(vars):x1,x2,y1,y2=varseq1=2x1-3f(y1)-4g(y2)+1eq2......
  • 2.4(学号:3025)
    importnumpyasnpimportmatplotlib.pyplotasplt定义x的范围x=np.linspace(-10,10,400)创建一个2行3列的子图布局fig,axs=plt.subplots(2,3,figsize=(12,8))遍历每个子图fork,axinenumerate(axs.flat,start=1):y=k*x**2+2*kax.plot(x,y,label......
  • 2.5(学号:3025)
    importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3D定义参数u和vu=np.linspace(-2,2,400)v=np.linspace(0,2*np.pi,400)U,V=np.meshgrid(u,v)根据参数方程计算x,y,zx=np.sqrt(1+U2+V2)*np.cos(V)y=np......
  • 2.6(学号:3025)
    importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3D模拟高程数据(假设数据已经过某种方式插值或生成)这里我们创建一个简单的40x50网格,并填充随机高程值x=np.linspace(0,43.65,40)y=np.linspace(0,58.2,50)X,Y=np.meshgr......
  • 2.7(学号:3025)
    importnumpyasnp定义系数矩阵A和常数项向量bA=np.array([[4,2,-1],[3,-1,2],[11,3,0]])b=np.array([2,10,8])使用numpy的lstsq求解最小二乘解x,residuals,rank,s=np.linalg.lstsq(A,b,rcond=None)print("最小二乘解为:")print(x)打印残差和矩阵A的......
  • 2.1(学号:3025)
    importnumpyasnpimportmatplotlib.pyplotasplt定义x的范围x=np.linspace(-5,5,400)计算三个函数的值y_cosh=np.cosh(x)y_sinh=np.sinh(x)y_half_exp=0.5*np.exp(x)创建图形和坐标轴plt.figure(figsize=(10,6))ax=plt.gca()绘制函数ax.plot(x,......