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;
    }
  • 相关阅读:
    javascript实现俄罗斯方块游戏
    HTML5 SSE 数据推送应用开发
    一次实习生面试经历
    前端工作面试问题(上)
    关于写好这个“简历”的几点思考
    ROS机器人的系统构建-连接摄像头、连接kinect、连接激光雷达
    opencv 轮廓的外围多边形提取或者 删除最小最大轮廓
    opencv 轮廓点的坐标大小的修改
    opencv 轮廓的外围多边形提取或者删除最小最大轮廓
    opencv 容器的使用vector<std::vector<cv::Point>> or 轮廓存储到容器中
  • 原文地址:https://www.cnblogs.com/pk28/p/5759201.html
Copyright © 2011-2022 走看看