求助,E题为什么存dx,dy不行

from collections import *
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
c = defaultdict(list)
for i in range(n):
    x1, y1 = xy[i]
    for j in range(i + 1, n):
        x2, y2 = xy[j]
        dx, dy = x2 - x1, y2 - y1
		# 把dx变成正的存储
        if dx < 0:
            dx, dy = -dx, -dy
        c[(dx, dy)].append((i, j))
res = -1
for ci in c:
    m = len(c[ci])
    if m <= 1:
        continue
	# 选两个能构成平行四边形的边求面积
    for i in range(m):
        for j in range(i+1, m):
            if c[ci][j][0] in c[ci][i] or c[ci][j][1] in c[ci][i]:
                continue
            x, y = [], []
            for k in c[ci][i]:
                x.append(xy[k][0])
                y.append(xy[k][1])
            for k in c[ci][j]:
                x.append(xy[k][0])
                y.append(xy[k][1])
            x.sort(), y.sort()
            s = (x[2]-x[1])*(y[2]-y[1])+(y[3]-y[2])*(x[2]-x[0])+(y[3]-y[1])*(x[3]-x[2])
            res = max(res, s)
if res < 0:
    print(-1)
else:
    print(str(res)+".0")

全部评论

相关推荐

YanSu!:技术岗还有群面???
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
10-25 11:19
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务