我的資料

2015年7月19日 星期日

UVa 591 : Box of Bricks

好吧,我又出現了呢~~今天寫了三題水題
不過不知道能不能夠在今天以前把這三題的"攻略"都寫完ㄟ
可能要看今天 Trove 能不能順利進去吧 ( 喂





這次要講的題目是 UVa 591 : Box of Bricks
原文網址 :
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=532

至於題目方面因為滿簡單的 ( 連我都看得懂啊!! ),所以我就不解釋了

這題其實只要計算積木的平均值,再直接把大於 ( 或小於,都一樣 ) 的部分加起來,就是答案了
我這次用了 vector 來儲存各堆積木的數量,我覺得用 vector 看起來比較酷
之後有時間的話我應該也會打幾篇關於 STL 的介紹......吧 XDD


#include <iostream>
#include <stdio.h>
#include <vector>
 
using namespace std;
 
int main()
{
    int n;
    int Set = 1;
    while (cin >> n && n)
    {
        int total = 0,ans = 0;
        vector<int> record;
        for (int i=0;i<n;i++)
        {
            int temp;
            cin >> temp;
            record.push_back(temp);
            total += temp;
        }
        total /= n;
        for (int i=0;i<record.size();i++)
        {
            if (record[i] > total)
                ans += ( record[i] - total );
        }
        cout << "Set #" << Set << endl;
        printf("The minimum number of moves is %d.\n\n",ans);
        Set ++ ;
    }
    return 0;
}


後記 :

這一篇其實還滿快的,雖然主因是因為沒什麼講解啦~~ XD
那就先這樣囉~~

沒有留言:

張貼留言