Link: Codeforces 388A Fox and Box Accumulation
N boxes are provided. Each box tells you that you can put at most a few boxes on the box and asks how many boxes are needed.
Solution: x is only 105 at the maximum. Use a cnt array to record the number of each box, and then add the number from the smallest until it cannot be added.
# Include
# Include
# Include using namespace std; const int N = 105; int n, cnt [N], tmp; void init () {int a; tmp = 0; scanf ("% d", & n); for (int I = 0; I <n; I ++) {scanf ("% d", & ); tmp = max (a, tmp); cnt [a] ++ ;}} void set (int x, int c) {if (x> tmp) return; if (c> x | cnt [x] = 0) {set (x + 1, c);} else {cnt [x] --; set (x, c + 1) ;}} int solve () {int ans = 0; for (int I = 0; I <= tmp; I ++) {while (cnt [I]) {set (I, 0); ans ++ ;}} return ans ;}int main () {memset (cnt, 0, sizeof (cnt); init (); printf ("% d \ n", solve (); return 0 ;}