题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度分析:blablabla
C++ 代码
#include <iostream>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long LL;
LL q[maxn];
int n;
int main(){
cin >> n;
for (int i = 0; i < n; i++){
scanf ("%lld", &q[i]);
}
int count = 0;
for (int i = 0; i < n; i++){
count = 0;
for (int j = 0; j <= 32; j++)
if((q[i] >> j) & 1) count++;
cout << count << " ";
}
cout << endl;
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度分析:blablabla
C++ 代码
#include <iostream>
using namespace std;
int n, count;
int main(){
cin >> n;
while (n--){
count = 0;
int x;
cin >> x;
for (int i = x; i; i -= i & -i)// i & -i 返回左右向左起第i个1,i-=这个东西,相当于每次减去一个1,直到i == 0
count ++;
cout << count << " ";
}
return 0;
}