第一题:
代码如下:
def ac(b): max1=max(b) if max1 < (sum(b)-max1): return True else: return False n=int(input().strip()) length=[int(i) for i in input().strip().split(" ")] target=-1 if n==3: if ac(length): target=n else: for i in range(3,n,1): if ac(length[:i]): target=i break print(target)
第二题:
代码如下:
def ac(k,n): list1=[] while n!=0: list1.append(n%k) n=n//k list1=list(reversed(list1)) dic={} for i in list1: if i not in dic: dic[i]=0 dic[i]+=1 if k-1 not in dic: return 0 else: return dic[k - 1] q=int(input().strip()) query=[] for i in range(q): query.append([int(i) for i in input().strip().split(" ")]) for que in query: k=que[0] time=0 num=0 for i in range(que[1],que[2]+1): if time < ac(k,i): time=max(time,ac(k,i)) num=i print(num)
第三题:
代码如下:
n=int(input().strip()) list1=[int(i) for i in input().strip().split(" ")] sum=0 for i in range(len(list1)): for j in range(i+1,len(list1),1): sum+=(abs(list1[i]-list1[j])) print(sum*4)
完结