CSP:小明种苹果
满分代码:
#include <iostream>
using namespace std;
int n, m;
int idx = 0; // 疏果最多的树的编号
int mn = 0; // 疏果最多的数目
int ans = 0; // 剩下的果数
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
int num = 0;
for (int j = 0; j <= m; ++j) {
int temp;
cin >> temp;
if (j != 0) {
num += temp;
}
else {
ans += temp;
}
}
if (num < mn) {
idx = i;
mn = num;
}
ans += num;
}
cout << ans << " " << idx << " " << (-mn) << endl;
return 0;
}
这篇博客介绍了一道CSP(Contest Software Problem)题目,涉及到一个苹果疏果的情况。代码实现了一个求解过程,通过遍历每棵树的苹果数量,找到疏果最多的树,并计算剩余的苹果总数。最终输出疏果最多树的编号、疏果数量和剩余的果数。这是一篇关于算法和数据结构的实战解析。

被折叠的 条评论
为什么被折叠?



