C. Fox and Box Accumulation
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
3
0 0 10
output
2
input
5
0 1 2 3 4
output
1
input
4
0 0 0 0
output
4
input
9
0 1 0 2 0 1 1 2 10
output
3

这题的贪心得逆向考虑,就是从小到大贪心,先看小的 a[i]值,看后面有没有能承受住这个箱子的其他箱子,如果有那么叠加箱子的数量,接着找。

/* ***********************************************
Author :guanjun
Created Time :2016/8/10 22:51:00
File Name :cf228c.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int a[maxn];
int vis[maxn];
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n;
cle(vis);
cin>>n;
for(int i=;i<=n;i++)cin>>a[i];
sort(a+,a++n);
int ans=;
for(int i=;i<=n;i++){
if(!vis[i]){
int num=;
for(int j=i+;j<=n;j++){
if(a[j]>=num&&!vis[j]){
num++;vis[j]=;
}
}
ans++;
}
}
cout<<ans<<endl;
return ;
}

Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation的更多相关文章

  1. Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心

    A. Fox and Box Accumulation 题目连接: http://codeforces.com/contest/388/problem/A Description Fox Ciel h ...

  2. Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)

    题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...

  3. Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈

    C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playi ...

  4. Codeforces Round #228 (Div. 1) B. Fox and Minimal path 构造

    B. Fox and Minimal path 题目连接: http://codeforces.com/contest/388/problem/B Description Fox Ciel wants ...

  5. Codeforces Round #228 (Div. 1) 388B Fox and Minimal path

    链接:http://codeforces.com/problemset/problem/388/B [题意] 给出一个整数K,构造出刚好含有K条从1到2的最短路的图. [分析] 由于是要自己构造图,当 ...

  6. Codeforces Round #228 (Div. 2) B. Fox and Cross

    #include <iostream> #include <string> #include <vector> #include <algorithm> ...

  7. Codeforces Round #228 (Div. 2) A. Fox and Number Game

    #include <iostream> #include <algorithm> #include <vector> #include <numeric> ...

  8. Codeforces Round #228 (Div. 2)

    做codeforces以来题目最水的一次 A题: Fox and Number Game 题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值 sol: 简单数论题目,直接求所有 ...

  9. Codeforces Round #228 (Div. 1) A

    A. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. 原生js上传图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 安装Vmware Tools出现错误

    安装Vmware Tools出现: Before you can compile modules, you need to have the following installed... makegc ...

  3. linux下安装flash player

    下载flash player,选择.tar.gz for other linux. 网址:http://get.adobe.com/flashplayer/ Ctrl+Alt+T进入终端: 进入下载所 ...

  4. 编译时报错,找不到指定路径下的command,而路径是正确的。

    使用的Fedora 18 64位的系统kernel,内核为3.6.10.按照要求使用yum install *** 安装各项工具. path路径使用提供的toolchain,各种路径也安装正确,却发现 ...

  5. 60. Spring Boot写后感【从零开始学Spring Boot】

    从2016年4月15日到2016年7月20日经历长达3个月的时间,[从零开始学习Spring Boot]系列就要告一段落了.国内的各种资源都比较乱或者是copy 来copy去的,错了也不加以修正下,导 ...

  6. 2018/2/16 解析Logback的AppenderBase源码,并举一反三的实现Logback扩展功能的思路,以及它的实际业务应用场景

    在学习Logback的过程中,知道了它有一个可以将日志往第三方数据源写的功能,这个功能的实现就是这个AppenderBase类,不禁想看看它的源码. 下面是AppenderBase类的所有子类(也就是 ...

  7. Jquery判断某个字符串是否在数组中

    使用$.inArray方法判断,如果存在则返回0,不存在返回-1,结果如下: 另外也可以将数组转为字符串,并使用正则表达式处理

  8. I - Balancing Act POJ - 1655

    Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the t ...

  9. [bzoj3712][PA2014]Fiolki_倍增LCA

    Fiolki bzoj-3712 PA-2014 题目大意:题目链接. 注释:略. 想法: 神题! 我们建树:对于一次倾倒操作,我们弄一个新的大瓶子作为两个合并瓶子的父亲节点,与两个瓶子相连. 对于一 ...

  10. HDU——1068 Girls and Boys

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...