• C. MP3(离散化 暴力)


    C. MP3

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of nn non-negative integers.

    If there are exactly KK distinct values in the array, then we need k=⌈log2K⌉k=⌈log2⁡K⌉ bits to store each value. It then takes nknk bits to store the whole file.

    To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l≤rl≤r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r][l;r], we don't change it. If it is less than ll, we change it to ll; if it is greater than rr, we change it to rr. You can see that we lose some low and some high intensities.

    Your task is to apply this compression in such a way that the file fits onto a disk of size II bytes, and the number of changed elements in the array is minimal possible.

    We remind you that 11 byte contains 88 bits.

    k=⌈log2K⌉k=⌈log2K⌉ is the smallest integer such that K≤2kK≤2k. In particular, if K=1K=1, then k=0k=0.

    Input

    The first line contains two integers nn and II (1≤n≤4⋅1051≤n≤4⋅105, 1≤I≤1081≤I≤108) — the length of the array and the size of the disk in bytes, respectively.

    The next line contains nn integers aiai (0≤ai≤1090≤ai≤109) — the array denoting the sound file.

    Output

    Print a single integer — the minimal possible number of changed elements.

    Examples

    input

    Copy

    6 1
    2 1 2 3 4 3
    

    output

    Copy

    2
    

    input

    Copy

    6 2
    2 1 2 3 4 3
    

    output

    Copy

    0
    

    input

    Copy

    6 1
    1 1 2 2 3 3
    

    output

    Copy

    2
    

    Note

    In the first example we can choose l=2,r=3l=2,r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2K=2, and the sound file fits onto the disk. Only two values are changed.

    In the second example the disk is larger, so the initial file fits it and no changes are required.

    In the third example we have to change both 1s or both 3s.

    比赛不知题中意,补题已是绿名人

    题目还是理解错了

    1.并不知道本题是可以离散化,以为只是找一个区间然后保证区间中的数最多

    2.以为可以将一个所有的位转换成一个大数,再将这个大数转换成x进制,x为任意,最后发现其实这个x只能是2^{x}

    将题目理解对了还是比较好写的

    #include <bits/stdc++.h>
    using namespace std;
    int a[400005];
    int mp[400005];
    int MAX=0;
    int sum[400005];
    int num;
    int main()
    {
        //freopen("in.txt","r",stdin);
        int n, I;
        cin >> n >> I;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &a[i]);
        }
        int cnt=0;
        sort(a + 1, a + 1 + n);
        a[0]=-1;
        for(int i=1;i<=n;i++)
        {
            if(a[i]==a[i-1])
            {
                mp[cnt]++;
            }
            else
            {
                mp[++cnt]++;
            }
        }
        for(int i=1;i<=cnt;i++)
        {
            sum[i]=sum[i-1]+mp[i];
        }
        int num=8*I/n;
        if(num>=19) printf("%d",0);
        else
        {
            num=1<<num;
            int cur;
            for(int i=1;i<=cnt;i++)
            {
                cur=min(cnt,i+num-1);
                MAX=max(MAX,sum[cur]-sum[i-1]);
            }
            printf("%d
    ",n-MAX);
        }
        
      }
  • 相关阅读:
    单机部署redis主从备份
    【 D3.js 进阶系列 — 2.1 】 力学图的事件 + 顶点的固定
    java生成二维码(带logo)
    求一个序列的全部排列
    【C/C++学院】(24)Oracle数据库编程--管理oracle
    php学习之道:mysql SELECT FOUND_ROWS()与COUNT(*)使用方法差别
    用"池"来提升对象的复用
    迷茫的一代人
    VMWARE安装MAC时无法移动鼠标?
    小心两个共享库共用同一个静态库
  • 原文地址:https://www.cnblogs.com/caowenbo/p/11852235.html
Copyright © 2020-2023  润新知