解题思路:
注意事项:
参考代码:
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二级辅导-阶乘数列 (C语言代码)浏览:541 |
蛇行矩阵 (C语言代码)浏览:563 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:684 |
整人!!浏览:838 |
C二级辅导-等差数列 (C语言代码)浏览:1216 |
简单的a+b (C语言代码)浏览:667 |
wu-理财计划 (C++代码)浏览:830 |
WU-判定字符位置 (C++代码)浏览:1395 |
简单的a+b (C语言代码)浏览:596 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:636 |