Codeforces CROC problem C

來源:互聯網
上載者:User

 

題意:給你一些 RMA 空間,要你使用這些 RAM 空間儲存數組,求可以儲存的數組個數的最大。。。

 

/*貪心。。 進一步理解二進位演算法 。。。 */ #include<iostream>#include<cmath>#include<cstdio>#include<algorithm>using namespace std;#define manx 1000009int a[32],b[manx];int main(){    int n,m;    while(cin>>n>>m){        for(int i=0;i<32;i++) a[i]=0;        for(int i=0;i<n;i++){            int x;            scanf("%d",&x);            for (int k=0; k<32; ++k) a[k] += x>>k&1;  //查看二進位是否存在         }            for(int i=0;i<m;i++)            scanf("%d",&b[i]);         sort(b,b+m);        int sum=0,i,j,k;        for( i=0;i<m;i++){            for(j=b[i]; j<32 && !a[j]; ++j);//找到第一個 a[j] 不為 0 的值             if(j==32) break;            ++sum; --a[j];            for(k=b[i]; k<j; ++k) ++a[k];//如果a[j]>b[k],處理剩下的a[j]-b[k]的空間                                          //由於二進位的特殊性,a[j]-b[i] 可以轉化為二進位的儲存        }        cout<<sum<<endl;    }}/*5 38 4 3 2 23 2 210 61 1 1 1 1 1 1 1 1 10 0 0 0 0 0*/

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.