CodeForces 388A Fox and Box Accumulation (模拟)

A. Fox and Box Accumulation

time limit per test:1 second

memory limit per test:256 megabytes

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 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

Note

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).

题目链接:http://codeforces.com/problemset/problem/388/A

题目大意:一些盒子,数字代表其上面最多还能放多少,且上面放的数字不能大于其下面的,问最少堆几堆

题目分析:暴力模拟,从上往下一堆一堆的取,详细见程序注释

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int a[105], hash[105];

int main()
{
    int n, ma = -1;
    memset(hash, 0, sizeof(hash));
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        ma = max(a[i], ma);
        hash[a[i]]++;
    }
    int ans = 0;
    while(n)
    {
        int cnt = 0; //第i堆的个数
        for(int i = 0; i <= ma; i++)
        {
            //有当前重量的,且其压力大于等于上面的个数
            //则将其放到下面
            while(hash[i] && i >= cnt)
            {
                hash[i] --; //放了一个,数量减1
                cnt++;      //这一堆数量加1
                n --;       //记录总的剩余个数
            }
        }
        ans ++;  //记录堆数
    }
    printf("%d\n", ans);
}
时间: 2024-08-24 19:33:09

CodeForces 388A Fox and Box Accumulation (模拟)的相关文章

CodeForces 388A Fox and Box Accumulation 贪心

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 cann

贪心/CoderForces 228c Fox and Box Accumulation

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int a[110]; 6 int main() 7 { 8 int n; 9 scanf("%d",&n); 10 for (int i=1;i<=n;i++) scanf("%d",&a[i]); 11 sort(a+1,a+n+1);

cf C. Fox and Box Accumulation

题意:输入一个n,然后输入n个数,问你可以划分多少个序列,序列为:其中一个数为c,在它的前面最多可以有c个数. 思路:先排序,然后对于每一个数逐步的找没有被用过的数,且这个数可以符合条件,然后如果没有找到,结果加1:最后就是答案. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int n; 7 int x[200]; 8 int num

贪心-codeforces-388A-Fox and Box Accumulation

Fox and Box Accumulation codeforces-388A 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 bo

Codeforces 97D Robot in Basement bitset+模拟

题目链接:点击打开链接 题意: 每个点有一个机器人(.),下面是一些指令,每次发出指令(一个字母)所有机器人都会执行移动. 当机器人到E点就会离开. 若机器人前方是'#' 或者边界则停留原地.一个方格可以站多个机器人. bitset模拟.. #include <cstdio> #include <cstring> #include <algorithm> #include <bitset> using namespace std; char s[100005

Codeforces 12D Ball 树状数组模拟3个元素的排序

题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<a

codeforces 459C Pashmak and Buses(模拟,组合数A)

题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostream> #include<algorithm> #include<string> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

Codeforces 309C Memory for Arrays 二进制模拟进位

题目链接:点击打开链接 题意: 给定n个箱子m个物品 下面n个数字表示箱子的容量 下面m个数字b1-bm 表示物品体积为2^bi大 问最多有多少个物品可以放入箱子. 思路: 贪心,先放小的,小的不能放再放大的 显然我们把n个箱子拆成二进制,然后模拟二进制减法运算. 剩下就是简单模拟 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<m

CodeForces 510 A. Fox And Snake(模拟啊 )

题目链接:http://codeforces.com/problemset/problem/510/A Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m