解题思路:
注意事项:
参考代码:
from cmath import inf n,k = map(int,input().strip().split()) A = [int(i) for i in input().strip().split()] B = [[-inf for j in range(3)] for i in range(k)] for i in A: temp = i % k if i > B[temp][0]: B[temp][2] = B[temp][1] B[temp][1] = B[temp][0] B[temp][0] = i elif i > B[temp][1]: B[temp][2] = B[temp][1] B[temp][1] = i elif i > B[temp][2]: B[temp][2] = i maxnum = -inf for i in range(0,k): for j in range(i,k): temp = (k - i - j) % k if len(set([i,j,temp])) == 2 and i == j: num = B[i][0]+B[i][1]+B[temp][0] if maxnum < num: maxnum = num elif len(set([i,j,temp])) == 2 and i == temp: num = B[i][0]+B[i][1]+B[j][0] if maxnum < num: maxnum = num elif len(set([i,j,temp])) == 2 and j == temp: num = B[i][0]+B[j][0]+B[j][1] if maxnum < num: maxnum = num elif len(set([i,j,temp])) == 3: num = B[i][0]+B[j][0]+B[temp][0] if maxnum < num: maxnum = num print(maxnum)
0.0分
2 人评分
拆分位数 (C语言代码)浏览:1328 |
不会做的浏览:874 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:1042 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:634 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:641 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:832 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:786 |
简单的a+b (C语言代码)浏览:419 |
1071题解浏览:493 |
C二级辅导-进制转换 (C语言代码)浏览:660 |