酷代码 AI
菜单
服务商

C++实现:Alan参加语法周赛的最佳时间分配得分程序

```cpp #include <iostream> #include <vector> int main() { std::vector<int> a(3), b(3), c(3), d(3); std::cin >> a[0] >> a[1] >> a[2]; std::cin >> b[0] >> b[1] >> b[2]; std::cin >> c[0] >> c[1] >> c[2]; std::cin >> d[0] >> d[1] >> d[2]; int maxScore = 0; int x1 = 0, x2 = 0, x3 = 0, x4 = 0; for (int i1 = 0; i1 <= 120; i1++) { for (int i2 = 0; i2 <= 120 - i1; i2++) { for (int i3 = 0; i3 <= 120 - i1 - i2; i3++) { int i4 = 120 - i1 - i2 - i3; int score = 0; if (i1 >= a[2]) score += 100; else if (i1 >= a[1] && i1 < a[2]) score += 60; else if (i1 >= a[0] && i1 < a[1]) score += 30; if (i2 >= b[2]) score += 100; else if (i2 >= b[1] && i2 < b[2]) score += 60; else if (i2 >= b[0] && i2 < b[1]) score += 30; if (i3 >= c[2]) score += 100; else if (i3 >= c[1] && i3 < c[2]) score += 60; else if (i3 >= c[0] && i3 < c[1]) score += 30; if (i4 >= d[2]) score += 100; else if (i4 >= d[1] && i4 < d[2]) score += 60; else if (i4 >= d[0] && i4 < d[1]) score += 30; if (score > maxScore) { maxScore = score; x1 = i1; x2 = i2; x3 = i3; x4 = i4; } } } } std::cout << x1 << " " << x2 << " " << x3 << " " << x4 << std::endl; return 0; } // 注意 1:输入数据时要确保数据的正确性和合法性。 // 注意 2:循环的边界条件要仔细检查,避免出现越界错误。 // 注意 3:对于得分的计算逻辑要清晰明确,确保能正确计算每种情况的得分。 ``` ######[AI写代码神器 | 708点数解答 | 2025-03-29 14:02:19]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]