题解 | #两条斜线#

两条斜线

https://ac.nowcoder.com/acm/problem/18951

x和y的差相同的都在一条直线上(斜率为1) x和y的和相同的都在一条直线上(斜率为1)

证明: 有两个点(x1,y1)(x2,y2) (y1-y2)/(x1-x2)=1 可得y1-x1 = y2-x2 (y1-y2)/(x1-x2)=-1 可得y1+x1 = y2+x2

枚举每一种差和每一种和,看对多的点的个数


n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

b1 = defaultdict(set)
b2 = defaultdict(set)
    
for i in range(n):
    b1[x[i]-y[i]].add(i)
    b2[x[i]+y[i]].add(i)
res = []
for i in b1.keys():
    for j in b2.keys():
        res.append(len(b1[i]|b2[j]))   
print(max(res))
全部评论

相关推荐

评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务