题目链接:https://www.luogu.org/problem/P2141
思路:把数据存在list中在set中也备份一下,两个for循环计算相加数字,在set中存在也就是符合题意的数据再存到另一个set中,最后set的长度就是我们要的ans
代码:
// An highlighted block
n=input().split()
l=input().split()
s=set(l)
l=list(s)
ans=set(l)
cnt=0
ans.clear()
for i in range(0,len(l)):
x=int(l[i])
for j in range(i+1,len(l)):
y=int(l[j])
if str(x+y) in s:
if str(x+y) in ans:
continue
else:
cnt+=1
ans.add(str(x+y))
print (len(ans))
以上終わりました。ご観覧ありがとうございます。