Hatena::Grouptopcoder

TopCoderの問題を解く

解いた問題の一覧表

2009-07-22

Inventory

| 19:55

問題文

30日間換算で1商品当たりいくつ売れるのかを計算。

const static double EPS = 1.0e-9;

class Inventory {
public:
    int monthlyOrder(vector <int> sales, vector <int> daysAvailable) {
        const static int DAYS_OF_MONTH = 30;
        double sum = 0;
        int availableItems = 0;
        for (int i = 0; i < sales.size(); i++) {
            if (daysAvailable[i] != 0) {
                sum += (static_cast<double>(sales[i])/daysAvailable[i])
                                                        * DAYS_OF_MONTH;
                availableItems++;
            }
        }
        return static_cast<int>(ceil(sum/availableItems-EPS));
    }
};