解题思路:
注意事项:
参考代码:
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语言代码)浏览:781 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:518 |
C语言程序设计教程(第三版)课后习题6.6 (C++代码)浏览:624 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:681 |
C二级辅导-温度转换 (C语言代码)浏览:718 |
复数求和 (C语言代码)浏览:916 |
简单的a+b (C语言代码)浏览:818 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:441 |
【计算直线的交点数】 (C语言代码)浏览:916 |
盐水的故事 (C语言代码)浏览:1524 |