zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 34 (Rated for Div. 2) C. Boxes Packing

    C. Boxes Packing

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.

    Mishka can put a box i into another box j if the following conditions are met:

    • i-th box is not put into another box;
    • j-th box doesn't contain any other boxes;
    • box i is smaller than box j (ai < aj).

    Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.

    Help Mishka to determine the minimum possible number of visible boxes!

    Input

    The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.

    The second line contains n integers a1a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.

    Output

    Print the minimum possible number of visible boxes.

    Examples

    input

    3
    1 2 3

    output

    1

    input

    4
    4 2 4 3

    output

    2
     

    题目大意:  小盒子可以放进比它大盒子,求这些盒子最后变成几个无法再组装的盒子

    正常AC代码:

    #include <stdio.h>
    #include <stdlib.h>
    #include <cmath>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <string>
    #include <ctype.h>
    //******************************************************
    #define lrt (rt*2)
    #define rrt  (rt*2+1)
    #define LL long long
    #define inf 0x3f3f3f3f
    #define pi acos(-1.0)
    #define exp 1e-8
    //***************************************************
    #define eps             1e-8
    #define inf             0x3f3f3f3f
    #define INF             2e18
    #define LL              long long
    #define ULL             unsigned long long
    #define PI              acos(-1.0)
    #define pb              push_back
    #define mk              make_pair
    
    #define all(a)          a.begin(),a.end()
    #define rall(a)         a.rbegin(),a.rend()
    #define SQR(a)          ((a)*(a))
    #define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
    #define min3(a,b,c)     min(a,min(b,c))
    #define max3(a,b,c)     max(a,max(b,c))
    #define min4(a,b,c,d)   min(min(a,b),min(c,d))
    #define max4(a,b,c,d)   max(max(a,b),max(c,d))
    #define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
    #define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
    #define Iterator(a)     __typeof__(a.begin())
    #define rIterator(a)    __typeof__(a.rbegin())
    #define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
    #define CasePrint       pc('C'); pc('a'); pc('s'); pc('e'); pc(' '); write(qq++,false); pc(':'); pc(' ')
    #define vi              vector <int>
    #define vL              vector <LL>
    #define For(I,A,B)      for(int I = (A); I < (B); ++I)
    #define FOR(I,A,B)      for(int I = (A); I <= (B); ++I)
    #define rFor(I,A,B)     for(int I = (A); I >= (B); --I)
    #define Rep(I,N)        For(I,0,N)
    #define REP(I,N)        FOR(I,1,N)
    using namespace std;
    const int maxn=1e5+10;
    vector<int>Q[maxn];
    const int MOD=1e9+7;
    int a[100005],vis[100005];
    int k=0;
    
    
    int main()
    {
        int n,x;
        while(~scanf("%d",&n))
        {
            memset(vis,0,sizeof(vis));
            Rep(i,n) scanf("%d",&a[i]);
            sort(a,a+n);
            int ans=0;
            for(int i=0;i<n;i++)
            {
                if(!vis[i])
                {
                    x=a[i],vis[i]=1;
                    for(int j=i+1;j<n;j++)
                    {
                        if(!vis[j])
                        {
                            if(x<a[j])
                            {
                                x=a[j],vis[j]=1;
                            }
                        }
                    }
                    ans++;
                }
            }
             cout<<ans<<endl;
        }
        return 0;
    }
    View Code

    map巧用,贼短的代码:

    #include<stdio.h>
    #include<iostream>
    #include<map>
    #define For(I,A,B)      for(int I = (A); I < (B); ++I)
    #define FOR(I,A,B)      for(int I = (A); I <= (B); ++I)
    #define rFor(I,A,B)     for(int I = (A); I >= (B); --I)
    #define Rep(I,N)        For(I,0,N)
    #define REP(I,N)        FOR(I,1,N)
    using namespace std;
    #define LL long long
    const int maxn=200000+10;
    LL a[maxn],sum[maxn];
    map<LL,LL>b;
    LL num,Max;
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            b.clear();
            Max=-1;
            REP(i,n)
            {
                scanf("%I64d",&num);
                b[num]++;
                Max=max(Max,b[num]);
            }
            cout<<Max<<endl;
        }
        return 0;
    }
     
     
     
  • 相关阅读:
    Caffe 编译
    Caffe 在 Ubuntu 中安装
    【转】git
    Using OpenCV with gcc and CMake
    【转】linux下安装opencv
    【转】shell 教程——07 Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
    【转】shell 教程——06 Shell变量:Shell变量的定义、删除变量、只读变量、变量类型
    python全栈开发-面向对象-初识2
    python全栈开发-面向对象-初识
    python全栈开发-前方高能-内置函数2
  • 原文地址:https://www.cnblogs.com/weimeiyuer/p/8030626.html
Copyright © 2011-2022 走看看