我用Python写了一个解法,各位大佬帮我看看哪里可以再优化优化

P1618 三连击(升级版)

WangDDUP @ 2022-10-26 13:24:21

numbers = []
values = []
import math
a,b,c = map(float,input().split())
def inter(a,b,c):
    if a&b or b&c or a&c:
        return True
    else:
        return False

#枚举所有三位数
for x in range(1,10):
    for y in range(1,10):
        for z in range(1,10):
            if x != y and y != z and x != z:
                numbers.append(100*x+10*y+z)

#在所有枚举的三位数中寻找合适的数字
def find_nums(numbers,a,b,c):
    for x in numbers:
        y = math.ceil((x/a)*b)
        z = math.ceil((x/a)*c)
        if (x in numbers) and (y in numbers) and (z in numbers):
            if x/y == a/b and y/z == b/c:
                if inter(set(str(x)),set(str(y)),set(str(z))):
                            continue
                values.append(x)
                values.append(y)
                values.append(z)
    return values

if int(a) == 0 or int(b) == 0 or int(c) == 0:
    print('No!!!')
else:
    values = find_nums(numbers,a,b,c)
        #将符合条件的数三个三个打印出来
    if values:
        for i in range(0,len(values),3):
            print(values[i],values[i+1],values[i+2])
    else:
        print('No!!!')

by a2lyaXNhbWUgbWFyaXNh @ 2022-10-26 13:39:29

wow You AK IOI and ICPC and CTSC tql %%% orz


by WangDDUP @ 2022-10-26 15:05:15

@S__B QAQ


|