2019年第十届蓝桥杯 - 省赛 - C/C++大学B组 - A. 组队
生活随笔
收集整理的這篇文章主要介紹了
2019年第十届蓝桥杯 - 省赛 - C/C++大学B组 - A. 组队
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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), 0for 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)Answer:490
總結
以上是生活随笔為你收集整理的2019年第十届蓝桥杯 - 省赛 - C/C++大学B组 - A. 组队的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2018第九届蓝桥杯C/C++ B国赛
- 下一篇: 2019第十届蓝桥杯C/C++ B组省赛