zoukankan      html  css  js  c++  java
  • 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
    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 << 61;
    const double eps=1e-5;
    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=1;i<=n;i++)cin>>a[i];
        sort(a+1,a+1+n);
        int ans=0;
        for(int i=1;i<=n;i++){
            if(!vis[i]){
                int num=1;
                for(int j=i+1;j<=n;j++){
                    if(a[j]>=num&&!vis[j]){
                        num++;vis[j]=1;
                    }
                }
                ans++;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
  • 相关阅读:
    Spring注释事务失效及解决办法
    在使用springMVC时,我使用了@Service这样的注解,发现使用注解@Transactional声明的事务不起作用
    如何在Oracle中复制表结构和表数据
    Tomcat Deployment failure ,locked one or more files
    java中对List中对象排序实现
    HDU 5002 Tree LCT 区间更新
    2014-2015 ACM-ICPC, Asia Xian Regional Contest G The Problem to Slow Down You 回文树
    Codeforces Round #323 (Div. 1) B. Once Again... 暴力
    Codeforces Round #323 (Div. 2) C. GCD Table 暴力
    hdu 5497 Inversion 树状数组 逆序对,单点修改
  • 原文地址:https://www.cnblogs.com/pk28/p/5759201.html
Copyright © 2011-2022 走看看