#45667: 這題還算簡單,適配小蜜蜂的智商


1121226@stu.wghs.tp.edu.tw (Arthur✨小蜜蜂)

學校 : 臺北市私立薇閣高級中學
編號 : 252772
來源 : [60.248.154.143]
最後登入時間 :
2025-04-09 15:55:05
c067. 00591 - Box of Bricks -- UVa591 | From: [112.104.66.104] | 發表日期 : 2025-03-29 14:48

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    int set=1;  // 測試組數計數器
    while (cin>>n&&n!=0) {
        int blocks[n]; // 儲存每堆方塊的高度
        int sum=0;  // 總方塊數量
        for (int i=0;i<n;i++){
            cin>>blocks[i];
            sum+=blocks[i];
        }
        int average=sum/n; // 計算平均高度
        int moves=0; // 計算需要移動的方塊數
        for (int i=0;i<n;i++){
            if (blocks[i]>average){ // 只計算高於平均值的部分
                moves+=blocks[i]-average;
            }
        }
        cout<<"Set #"<<set<<endl;
        cout<<"The minimum number of moves is "<<moves<<"."<<endl<<endl;
        set++;  // 增加測試組數
    }
    return 0;
}


 
ZeroJudge Forum