zoukankan      html  css  js  c++  java
  • 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=log2Kk=⌈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 lrl≤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=log2Kk=⌈log2K⌉ is the smallest integer such that K2kK≤2k. In particular, if K=1K=1, then k=0k=0.

    Input

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

    The next line contains nn integers aiai (0ai1090≤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.

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int maxn=4e5+10;
    int n;
    ll I;
    int c[maxn];
    int res=0x3f3f3f3f;
    int main() {
        freopen("1.txt","r",stdin);
        scanf("%d%d",&n,&I);
        for(register int i=1;i<=n;++i){
            scanf("%d",c+i);
        }
        sort(c+1,c+1+n);
        I=(I*8)/n;
        I=I>30?(1<<30):(1<<I);
        int l=1,r=1;
        int sum=1;
        while (r<=n){
            while (sum>I){
                l++;
                if(c[l]!=c[l-1]){
                    sum--;
                }
            }
            res=min(res,n-(r-l+1));
            r++;
            if(c[r]!=c[r-1])sum++;
        }
        printf("%d
    ",res);
        return 0;
    }
  • 相关阅读:
    HTTP, W3SVC, WAS 和 W3WP
    SQL Server 阻塞分析
    译文: async/await SynchronizationContext 上下文问题
    译文:TransactionScope 与 Async/Await
    ASP.NET MVC 后台接收集合参数和 jquery ajax 传值
    EntityFramework 异常 -- An entity object cannot be referenced by multiple instances of IEntityChangeTracker
    【理财学习日记】(一)人生穷富的关键
    【理财学习日记】下决心去学习理财,去支配生活
    web.config文件中自定义配置节点
    Mysql表的碎片整理和空间回收
  • 原文地址:https://www.cnblogs.com/czy-power/p/11274403.html
Copyright © 2011-2022 走看看