竞赛讨论区 > 求问python怎么写不会时间超限啊?!
头像
WynnLu
发布于 2020-02-06 19:48
+ 关注

求问python怎么写不会时间超限啊?!

不管是递归求所有三角形还是三个for循环嵌套都时间超限
这咋办嘛
def isObtuse(a, b, c):
    return ((b[0] - a[0]) * (c[0] - a[0]) + (b[1] - a[1]) * (c[1] - a[1]) < 0) and ((b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]) != 0)
    
def solve():
    n = int(input())
    locations = []
    count = 0
    for _ in range(n):
        x, y = map(int, input().split())
        locations.append((x, y))
    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if isObtuse(locations[i], locations[j], locations[k])&nbs***bsp;isObtuse(locations[k], locations[i], locations[j])&nbs***bsp;isObtuse(locations[j], locations[i], locations[k]):
                    count += 1
    print(count)
    
solve()

求大佬教我

全部评论

(4) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐