阿里4.15笔试
感觉都挺简单,就是想不到,太菜了。
第一题AC,第二题暴力超时10%AC
第一题:
if __name__ == "__main__": n = int(sys.stdin.readline().strip()) line = sys.stdin.readline().strip() values = list(map(int, line.split())) values.sort() res = [] tag = 1 for i in range(len(values)): if tag == 1: res.append(values.pop(-1)) tag = 0 elif tag == 0: res.append(values.pop(0)) tag = 1 sum = 0 for i in range(len(res)): if i == 0: sum += abs(res[i] - res[1]) sum += abs(res[i] - res[-1]) elif i == len(res) - 1: sum += abs(res[i]-res[0]) sum += abs(res[i]-res[i-1]) else: sum += abs(res[i]-res[i-1]) sum += abs(res[i] - res[i+1]) print(sum//2) for i in res: print(str(i)+' ', end='')第二题:
if __name__ == "__main__": n = int(sys.stdin.readline().strip()) values = [] for i in range(n): line = sys.stdin.readline().strip() value = list(map(int, line.split())) values.append(value) min_vals = [] for x1, y1 in values: for x2, y2 in values: if x1 == x2 and y1 == y2: continue X = (x1 + x2)/2.0 Y = (y1 + y2)/2.0 min_val = min(X, Y) min_vals.append(min_val) print('%.1f'%max(min_vals))