hdu1725大水题

贪心就可以了,题目公式排版混乱,半天才读懂题。。。

/*
 * hdu1725/win.cpp
 * Created on: 2012-7-6
 * Author    : ben
 */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;

int facts[13] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800,
        39916800, 479001600 };

int main() {
#ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
#endif
    int T, M;
    scanf("%d", &T);
    while(T--) {
        scanf("%d", &M);
        int ans = 0;
        for(int i = 12; i > 0; i--) {
            if(M == 0) {
                break;
            }
            if(M >= facts[i]) {
                ans += M /facts[i];
                M = M % facts[i];
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
posted @ 2012-07-06 21:49  moonbay  阅读(125)  评论(0编辑  收藏  举报