import json from itertools import combinations import numpy as np # x+y≤4, x≤2, y≤3, x≥0, y≥0;每行对应一条半平面边界。 a = np.array([[1, 1], [1, 0], [0, 1], [-1, 0], [0, -1]]) b = np.array([4, 2, 3, 0, 0]) profit = np.array([3, 2]) best, value = None, -np.inf feasible_count = 0 for i, j in combinations(range(len(b)), 2): rows = [i, j] if abs(np.linalg.det(a[rows])) < 1e-12: continue # 平行边界没有唯一交点。 point = np.linalg.solve(a[rows], b[rows]) if np.all(a @ point <= b + 1e-12): feasible_count += 1 if profit @ point > value: best, value = point, float(profit @ point) assert np.allclose(best, [2, 2]) and np.isclose(value, 10) result = {"point": best.tolist(), "value": value, "feasible_intersections": feasible_count} print("LAB_RESULT " + json.dumps(result, ensure_ascii=False))