A. 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 thanxi 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 test(s)
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

 二分pile的个数。
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <set>
using namespace std;
typedef long long LL ; int x[] , n ;
int pile[][] ;
int judge(int Len){
memset(pile,-,sizeof(pile)) ;
int row = n/Len , k = , i ,j;
for(i = ; i <= n/Len ; i++)
for(j = ; j <= Len ; j++)
pile[i][j] = x[k++] ;
if(n % Len){
row++ ;
j = ;
while(k < n)
pile[row][j++] = x[k++] ;
}
for(i = ; i <= Len ; i++){
for(j = ; j <= row ; j++){
if(pile[j][i] != - &&pile[j][i] < j - )
return ;
}
}
return ;
} int b_s(){
int L = ,R = n ,mid ,ans;
while(L <= R){
mid = (L + R)>> ;
if(judge(mid)){
ans = mid ;
R = mid - ;
}
else
L = mid + ;
}
return ans ;
} int main(){
int i ;
cin>>n ;
for(i = ; i < n ; i++)
cin>>x[i] ;
sort(x , x + n) ;
cout<<b_s()<<endl ;
return ;
}

Codeforces Round #228 (Div. 1) A的更多相关文章

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

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

  2. Codeforces Round #228 (Div. 1)

    今天学长给我们挂了一套Div.1的题,难受,好难啊. Problem A: 题目大意:给你n个数字,让你叠成n堆,每个数字上面的数的个数不能超过这个数,如 3 上面最多放三个数字 问你,最少能放几堆. ...

  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) A. Fox and Box Accumulation 贪心

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

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

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

  7. Codeforces Round #228 (Div. 2)

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

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

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

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

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

  10. Codeforces Round #228 (Div. 1) B

    B. Fox and Minimal path time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. Setup Spark source code environment

    1. Install Java and set JAVA_HOME 2. Install Eclipse Juno Java IDE, Scala plugin and Scala Test 3. D ...

  2. Android 命令管理项目

    今天介绍一下Android怎么用命令管理项目,用命令管理Android项目需要用到Android命令,首先介绍一下用Android命令创建新项目,打开命令提示窗口,导航到Android SDK 的to ...

  3. C# 顺序高斯(Gauss)消去法计算一元多次方程组

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. Similarity-based Learning

    Similarity-based approaches to machine learning come from the idea that the best way to make a predi ...

  5. hadoop map-red的执行过程

    hadoop的 map-red就是一个并行计算平台,我们在使用这个平台的时候,要做的事情就是提交自己定制的任务(job,主要定制map类,reduce类,combine类等类),然后设置job的各种参 ...

  6. 三部曲二(基本算法、动态规划、搜索)-1004-Instant Complexity

    Instant Complexity Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  7. 1、webservice的简单使用

    1.新建一个web端项目 2.点击添加项,选择web服务 3.在已经建好的项目中写一个方法 4.发布(发布方法选文件系统,web需要管理员权限) 生成文件夹: 5.配置IIS(略) 6.调用webse ...

  8. linux内核分析——扒开系统调用的三层皮

    万子惠 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 实验部分 选择2 ...

  9. RocketMQ消费者示例程序

    转载请注明出处:http://www.cnblogs.com/xiaodf/ 本博客实现了一个简单的RocketMQ消费者的示例,MQ里存储的是经过Avro序列化的消息数据,程序读取数据并反序列化后, ...

  10. set的应用

    头文件 ;#include <set> 简单应用: begin()     返回set容器的第一个元素 end()   返回set容器的最后一个元素 clear()        删除se ...