Run ID:121795

提交时间:2025-06-08 11:34:43

#include <iostream> using namespace std; int main() { int balls[7]; // 红、黄、绿、棕、蓝、粉、黑 for (int i = 0; i < 7; i++) { cin >> balls[i]; } int red = balls[0]; // 红球数量 int colors[6] = { // 其他彩球数量 balls[1], // 黄(2分) balls[2], // 绿(3分) balls[3], // 棕(4分) balls[4], // 蓝(5分) balls[5], // 粉(6分) balls[6] // 黑(7分) }; int color_scores[6] = {2, 3, 4, 5, 6, 7}; // 各彩球对应分数 int max_score = 0; // 阶段一:红球和彩球交替击打 while (red > 0) { // 每次击打一个红球(1分) max_score += 1; red--; // 然后击打最高分的彩球 bool color_hit = false; for (int i = 5; i >= 0; i--) { if (colors[i] > 0) { max_score += color_scores[i]; color_hit = true; break; } } if (!color_hit) { // 如果没有彩球可打,只能结束 break; } } // 阶段二:按分值从低到高击打剩余彩球 for (int i = 0; i < 6; i++) { if (colors[i] > 0) { max_score += colors[i] * color_scores[i]; } } cout << max_score << endl; return 0; }