设以第一种方法合成装备m件,以第二种方法合成装备n件,则消耗2m+4n件材料a和3m+n件材料b。题目转化为求满足约束条件: 的m + n最大值。
运用高中所学简单线性规划知识,得到(m, n)所满足的区域,分三种情况
(1)
图片说明
(2)
图片说明
(3)
图片说明
设z = m + n,再次运用线性规划知识,根据n = z - m求得z最大值,再分情况取整数即可

import math
t = int(input())
for k in range(t):
    x, y = input().split()
    x, y = int(x), int(y)

    if y <= x / 4:
        print(y)
    elif x / 2 <= y / 3:
        print(math.floor(x / 2))
    else:
        n = (3 * x - 2 * y) / 10
        m = (4 * y - x) / 10
        n_floor = math.floor(n)
        m_floor = math.floor(m)
        n_ceil = math.ceil(n)
        m_ceil = math.ceil(m)
        if 2 * m_ceil + 4 * n_ceil <= x and 3 * m_ceil + n_ceil <= y:
            print(m_ceil + n_ceil)
        elif 2 * m_floor + 4 * n_ceil <= x and 3 * m_floor + n_ceil <= y:
            print(m_floor + n_ceil)
        elif 2 * m_ceil + 4 * n_floor <= x and 3 * m_ceil + n_floor <= y:
            print(m_ceil + n_floor)
        elif 2 * m_floor + 4 * n_floor <= x and 3 * m_floor + n_floor <= y:
            print(m_floor + n_floor)
        else:
            print("err")