京东算法笔试求交流
1.股票,求最小损失。时间超时,27%
n,m = list(map(int,input().strip().split())) readarr = list(map(int,input().strip().split()))[:n] num = int(input().strip()) readarr.sort() try: for j in range(num): choose = int(input().strip()) arr = readarr[:choose][::-1] sum = 0 for i in range(len(arr)): sum += ((i // m) + 1) * arr[i] print(str(int(sum))) except: pass2.求点组成的平行线段个数。通过67%,感觉自己题意理解的有点问题
#!/bin/python # -*- coding: utf8 -*- import sys import os import re def fun(n): temp = [] re = {} re['inf']=0 for i in range(n): x, y = list(map(int, input().strip().split()))[:2] if len(temp)==0: temp.append([x,y]) else: for tem in temp: if (tem[0]-x)==0: re['inf'] += 1 elif (tem[1]-y)/(tem[0]-x) not in re: re[(tem[1]-y)/(tem[0]-x)] = 1 else: re[(tem[1] - y) / (tem[0] - x)] += 1 temp.append([x, y]) count = 0 m = 0 for k,v in re.items(): if v>m: m = v print((m)*(m-1)//2) if __name__=="__main__": n = int(input().strip()) fun(n)