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 ...
随机推荐
- 自己写了一个类似百度空间自动保存草稿的程序 php+jquery
可以异步加载mysql中的草稿~,异步更新草稿列表~ 下载地址:http://download.csdn.net/source/3479156 代码: demo.php <?php mysql_ ...
- VC远控(一)界面设计及套接字连接测试
首先创建一个MFC项目. 选择基于对话框: 勾选Windows套接字 依次拉上各种不同的控件: Edit Control.Button.Tree.Static Text.List.Progress C ...
- 答 “SOA会不会造成IT黑洞?”
[文/ 任英杰] 随意间看到支点网的“SOA会不会造成IT黑洞”一文,作者对SOA的认识颇有以偏概全之嫌,写点自己的感想,作为应和吧. 作者的二个对SOA的观点有些偏颇:“SOA就是一种系统集成,它是 ...
- PHP相关图书推荐
PHP和MySQL Web开发(原书第4版) 作 者 [澳] Luke Welling,[澳] Luke Welling 著:武欣 等 译 出 版 社 机械工业出版社 出版时间 2009-0 ...
- 把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend
//把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend //dp[i][j]:把第i个数转成第j小的数,最小花费 //此题与po ...
- C# 关闭 Excel进程
namespace ExcelTest { class DataOutput { static void Main(string[] args) ...
- Android 相关
ADT 下载更新 http://www.oschina.net/question/1463998_220998 更改包名后,资源文件不更新 AndroidMainfast.xml文件,有package ...
- Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
mvn war:war命令出错: 原因: maven的web项目默认的webroot是在src\main\webapp.如果在此目录下找不到web.xml就抛出以上的异常. 解决方案: 在pom.xm ...
- ArcObjects10.0MapControl不显示地图内容
添加MapControl控件,右键属性设置MXD 文档之后,运行显示一片空白.拖放另一个控件axLicenseControl之后OK.
- Java基础String类
String是一个对象 String不属于8种基本数据类型(byte, char, short, int, float, long, double, boolean),String是对象,所以其默认值 ...