Ideas
唉,大一的时候做这种题就是写这种代码,那时候觉得好垃圾。
大四了再做这种题还写这种代码,哈哈哈。
这题其实没啥,就是读文件,然后循环+check就完了,需要注意第一列时编号。
代码
C++
#include <iostream>
#include <cstdio>
using namespace std;
int team[20][6] = {
{1, 97, 90, 0, 0, 0},
{2, 92, 85, 96, 0, 0},
{3, 0, 0, 0, 0, 93},
{4, 0, 0, 0, 80, 86},
{5, 89, 83, 97, 0, 0},
{6, 82, 86, 0, 0, 0},
{7, 0, 0, 0, 87, 90},
{8, 0, 97, 96, 0, 0},
{9, 0, 0, 89, 0, 0},
{10, 95, 99, 0, 0, 0},
{11, 0, 0, 96, 97, 0},
{12, 0, 0, 0, 93, 98},
{13, 94, 91, 0, 0, 0},
{14, 0, 83, 87, 0, 0},
{15, 0, 0, 98, 97, 98},
{16, 0, 0, 0, 93, 86},
{17, 98, 83, 99, 98, 81},
{18, 93, 87, 92, 96, 81},
{19, 0, 0, 0, 89, 92},
{20, 0, 99, 96, 95, 81}
};
int main() {
int ans = 0;
for (int i = 0; i < 20; ++i) {
for (int j = 0; j < 20; ++j) {
if (j != i)
for (int k = 0; k < 20; ++k) {
if (k != j && k != i)
for (int l = 0; l < 20; ++l) {
if (l != k && l != j && l != i)
for (int m = 0; m < 20; ++m) {
if (m != l && m != k && m != j && m != i) {
if (team[i][1] + team[j][2] + team[k][3] + team[l][4] + team[m][5] > ans)
ans = team[i][1] + team[j][2] + team[k][3] + team[l][4] + team[m][5];
}
}
}
}
}
}
cout << ans << endl;
return 0;
}
Python
if __name__ == '__main__':
team = []
with open("./team.txt", 'r') as fp:
for line in fp.readlines():
line = line.strip("\n").strip(',')
team.append(eval(line))
peoples, ans = len(team), 0
for a in range(peoples):
for b in range(peoples):
if b != a:
for c in range(peoples):
if c != b and c != a:
for d in range(peoples):
if d != c and d != b and d != a:
for e in range(peoples):
if e != d and e != c and e != b and e != a:
ans = max(ans, team[a][1] + team[b][2] + team[c][3] + team[d][4] + team[e][5])
print(ans)