Codeforces CROC problem C
来源:互联网 发布:金华亿途网络 编辑:程序博客网 时间:2024/06/14 00:01
题意:给你一些 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*/
- Codeforces CROC problem C
- Codeforces CROC 2016 - Elimination Round
- [Codeforces]C. Commentator problem
- Codeforces Problem 332C
- CodeForces #174.div2.problem C
- CodeForces #181.div2.problem C
- codeforces 2C Commentator problem
- codeforces/problem/175/C 贪心
- codeforces 2C Commentator problem
- Codeforces-706C Hard problem
- CodeForces 706C Hard problem
- 【Codeforces 706C . Hard problem】
- codeforces 706C Hard problem
- codeforces-367# C. Hard problem
- Codeforces 706C Hard problem
- codeforces /782/problem/C [dfs]
- Codeforces 2C Commentator problem
- Problem - 363C - Codeforces --C. Fixing Typos
- linux实用PF_PACKET接收原始链路层数据包
- log4cplus的一些问题
- No enclosing instance of type SearchCommand is available due to some intermediate constructor invoca
- java web strusts2 配置中的问题
- 特征选择常用算法综述
- Codeforces CROC problem C
- Oracle:外键关联导致数据无法删除
- 利用NFS服务挂载NFS根文件系统
- Android通过JNI调用驱动程序(完全解析实例)
- 使用Gnu gprof进行Linux平台下的程序分析
- 约瑟夫问题
- 贪心之hdu1045
- WCF足迹10:异常2
- Python3中bytes和HexStr之间的转换