求大佬告知第二题究竟是什么情况,我测试了用例感觉没问题。感觉题没描述清楚,第一行的数字表示什么,测试次数?又没说明。。
# -*- coding:utf-8 -*- import sys import math class Solution(object): def __init__(self, n, data): self.setA = [] self.setB = [] self.n = n for i in range(n): t = data.pop(0) self.setA.append((t[0], t[1])) for i in range(n): t = data.pop(0) self.setB.append((t[0], t[1])) def findMin(self): minValue = float('inf') self.setA.sort() self.setB.sort() while self.setA: tmp = self.setA.pop(0) for i in range(len(self.setB)): x = tmp[0] - self.setB[i][0] y = tmp[1] - self.setB[i][1] v = x ** 2 + y ** 2 if x > 0 and y > 0 and v >= minValue: break minValue = min(v, minValue) out = str(math.sqrt(minValue)) if '.' in out: index = out.index('.') if len(out) - index < 3: out += '0'*(len(out)-index) else: out = out[:index+4] else: out += ".000" print(out) if __name__ == "__main__": dataIn = [] while True: line = sys.stdin.readline().strip() if not line: break dataIn.append(map(int, line.split())) cnt = dataIn.pop(0)[0] for c in range(cnt): if not dataIn: break l = dataIn.pop(0)[0] s = Solution(l, dataIn[0:2 * l]) s.findMin() dataIn = dataIn[2 * l:]
全部评论
(2) 回帖