第四题,我的思路和楼主基本一致,找差值。但是我统计有多少个完美对,是处理一行数据 统计过往中它的相反差值有几个,然后count加上去,本地自测没问题,就是提交后通过为0。大家能帮忙看看嘛 if __name__ == "__main__": n, k = map(int, input().split()) dict = {} count = 0 for i in range(n): lst = list(map(int, input().split())) diff = [] reverse_diff = [] for j in range(1,k): diff.append(lst[j]-lst[0]) reverse_diff.append( -1*( lst[j]-lst[0] ) ) diff = tuple(diff) reverse_diff = tuple(reverse_diff) if(diff not in dict.keys()): dict[diff] = 1 else: dict[diff] += 1 if(reverse_diff in dict.keys()): count += dict[reverse_diff] print(count)
点赞 2

相关推荐

10-22 19:18
上海大学 后端
jopajhhdjwnqk:水印都叠杀人书了
点赞 评论 收藏
分享
牛客网
牛客企业服务