Box of Bricks
唯一要注意的是输出换行是BETWEEN.
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int m;
int n;
int total;
int sets[55];
cin>>m;
while(m != 0){
total = 0;
for(int i = 0; i < m; i++){
cin>>n;
sets[i] = n;
total = total + n;
}
int aver = total / m;
int distance = 0;
for(int i =0; i < m; i++){
distance += abs(sets[i] - aver);
}
cin>>m;
cout<<distance / 2<<endl;
if(m != 0){
cout<<endl;
}
}
system("pause");
}
本文提供了一个关于砖块盒子问题的C++实现方案。该方案通过计算每组砖块与平均值之间的距离来确定需要调整的最小次数,使得所有砖块组的砖块数尽可能接近平均值。代码实现了读取输入数据、计算距离并输出结果的功能。
768

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



