判断一组不等式是否满足约束并输出最大差
标题:判断一组不等式是否满足约束并输出最大差 | 时间限制:1秒 | 内存限制:65536K | 语言限制:不限
给定一组不等式,判断是否成立并输出不等式的最大差(输出浮点数的整数部分),要求:1)不等式系数为double类型,是一个二维数组;2)不等式的变量为int类型,是一维数组;3)不等式的目标值为double类型,是一维数组;4)不等式约束为字符串数组,只能是:">",">=","<","<=","=",例如,不等式组:
a11*x1+a12*x2+a13*x3+a14*x4+a15*x5<=b1;
a21*x1+a22*x2+a23*x3+a24*x4+a25*x5<=b2;
a11*x1+a12*x2+a13*x3+a14*x4+a15*x5<=b1;
a21*x1+a22*x2+a23*x3+a24*x4+a25*x5<=b2;
a31*x1+a32*x2+a33*x3+a34*x4+a35*x5<=b3;
def test(): try: while True: arr = input().strip().split(';') num = str(arr[-3]).split(',') b = str(arr[-2]).split(',') s = str(arr[-1]).split(',') max_item = [] false_res = [] i_range = len(arr) - 3 j_range = len(num) for i in range(0, i_range): item = str(arr[i]).split(',') sum = 0 res = float(b[i]) for j in range(j_range): sum = sum + float(item[j]) * float(num[j]) t = sum - res #max_i = int(abs(t)) max_i = int(t) max_item.append(max_i) if t == 0 and (s[i] == '=' or s[i] == '>=' or s[i] == '<='): fin_res = 'true' elif t > 0 and (s[i] == '>' or s[i] == '>='): fin_res = 'true' elif t < 0 and (s[i] == '<' or s[i] == '<='): fin_res = 'true' else: fin_res = 'false' false_res.append(fin_res) if 'false' in false_res: n = 'false' else: n = 'true' print(n,max(max_item)) except: pass test()