A. Fox and Box Accumulation
题目连接:
http://codeforces.com/contest/388/problem/A
Description
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100).
Output
Output a single integer — the minimal possible number of piles.
Sample Input
3
0 0 10
Sample Output
2
Hint
题意
有n个箱子,现在对于每一个箱子告诉你这个箱子的上面最多放多少个箱子
现在你需要使得箱子的列数最小,请问是多少
题解:
从表象来说,感觉像一个多背包问题,但实质上是不是的
这个东西显然是可以贪心的,因为这个箱子你用还是不用,对下一个用啥是没有影响的
所以直接贪心就好了
代码
#include<bits/stdc++.h> using namespace std; const int maxn = 105; int vis[maxn],ans; int a[maxn]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); sort(a+1,a+1+n); for(int i=1;i<=n;i++) { int pre = -1; for(int j=i;j<=n;j++) { if(vis[j])continue; if(a[j]>pre) { vis[j]=1; pre++; } } if(pre!=-1)ans++; } cout<<ans<<endl; }
来源:https://www.cnblogs.com/qscqesze/p/5451882.html