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), 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)

Answer:490

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大风车滴呀滴溜溜地转

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值