求问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()

求大佬教我
全部评论
问题不大,但是有可能会超时
8
送花
回复
分享
发布于 2020-12-12 12:52
很多题目用Python写时间不够。但算法用Python写是最自然的。建议放宽对Python的时间限制。
1
送花
回复
分享
发布于 2020-12-11 20:05
滴滴
校招火热招聘中
官网直投
暴力法最好不用python
点赞
送花
回复
分享
发布于 2020-02-07 14:29
请问楼主,&nbs***bsp 这块是什么意思呢,百度竟然都没找到😥
点赞
送花
回复
分享
发布于 2020-08-05 15:59

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务