A. Fox and Box Accumulation
1 second
256 megabytes
standard input
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?
The first line contains an integer n (1 ≤ n ≤ 100).
The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100).
Output a single integer — the minimal possible number of piles.
3
0 0 10
2
5
0 1 2 3 4
1
4
0 0 0 0
4
9
0 1 0 2 0 1 1 2 10
3
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
解题说明:模拟题,须要从上向下构造一个箱子堆,经过排序之后,首先保证最上面的都是最小的,其次是以下一层,直到最后遍历结束。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include <algorithm>
#include<cstring>
#include<string>
using namespace std; int main()
{
int n, i, k, d[105];
k = 0;
cin >> n;
for (i = 0; i<n; i++)
{
cin >> d[i];
}
sort(d, d + n);
for (i = 0; i<n; i++)
{
if (k*(d[i] + 1) <= i)
{
k++;
}
}
cout << k << endl;
return 0;
}
A. Fox and Box Accumulation的更多相关文章
- Codeforces 388A - Fox and Box Accumulation
388A - Fox and Box Accumulation 思路: 从小到大贪心模拟. 代码: #include<bits/stdc++.h> using namespace std; ...
- 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 ...
- CodeForces 388A Fox and Box Accumulation (模拟)
A. Fox and Box Accumulation time limit per test:1 second memory limit per test:256 megabytes Fox Cie ...
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
C. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces A. Fox and Box Accumulation 解题报告
题目链接:http://codeforces.com/problemset/problem/388/A 题目意思:有 n 个 boxes,每个box 有相同的 size 和 weight,但是stre ...
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)
题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...
- 388A Fox and Box Accumulation
一开始贪心策略想错了! #include<cstdio> #include<algorithm> using namespace std; ]; int main() { in ...
- cf C. Fox and Box Accumulation
题意:输入一个n,然后输入n个数,问你可以划分多少个序列,序列为:其中一个数为c,在它的前面最多可以有c个数. 思路:先排序,然后对于每一个数逐步的找没有被用过的数,且这个数可以符合条件,然后如果没有 ...
- 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 ...
随机推荐
- jquery元素定位方法
用chrome浏览器打开页面,按f12调出开发者调试模式,查看elements,部分代码如下图所示,注意红框部分 假设我们要查找某些元素的位置,用鼠标移到那部分元素,调试器会自动用蓝颜色标示选中部分的 ...
- CSS学习进度备忘
书签:“CSS 高级”跳过:另外跳过的内容有待跟进 __________________ 学习资源:W3School. _________________ 跳过的内容:1.“CSS id 选择器”的“ ...
- nagios监控远程主机服务可能出现的问题
1.使用插件NRPE监控命令不存在 在添加服务的时候,命令配置文件中需要传递一个参数,那么在监控服务配置文件中,需要添加一个!表示后面的为参数. 出现未定义的命令,查看被监控主机上的配置文件,添加监控 ...
- BITED数学建模七日谈之六:组队建议和比赛流程建议
今天进入数学建模经验谈第六天:组队建议和比赛流程建议 数学模型的组队非常重要,三个人的团队一定要有分工明确而且互有合作,三个人都有其各自的特长,这样在某方面的问题的处理上才会保持高效率. 三个人的分工 ...
- 通过AopTestUtils对切面对象进行mock
概述 当对一个切面类进行测试时,由于Spring对切面对象生成了proxy对象,此时对切面对象使用ReflectionTestUtils赋值,操作的是proxy对象,而不是真实对象,会使得赋值出问 ...
- Intel XDK问题
1.不能加入AndroidManifest.xml或者info.plist文件,没法设置特定信息,例如强制横屏. 2.不能自定义图表和启动loading界面
- 编辑器CocoStudio和CocosBuilder的对比
来源:http://4137613.blog.51cto.com/4127613/1352805 CocosBuilder CocoStudio 控件种类 支持大部分cocos2d-x自带的常用控 ...
- U盘分区信息清除
diskpart select disk 1 clean 清除选中(优U)盘的所有信息;
- <一道题>abc+cba=1333,求满足条件的abc的值,隐含条件a!=0,c!=0
这类东西,无非就是穷举法.见下面代码: #include <stdio.h> #include <stdlib.h> /* *abc + cba = 1333 * *a = ? ...
- python知识点 2014-07-09
迭代协议: 类实现方法__next__,则可以使用for.while来实现迭代 使用iter或者next实现手工迭代: L = [1,2,3] I = iter(L) print(I.next()) ...