题目:http://acm.hdu.edu.cn/showproblem.php?pid=2568
AC代码(C++):
#include <iostream> #include <queue> #include <set> #include <string> #include <algorithm> #include <string.h> #include <math.h> #define INF 0x3f3f3f3f #define eps 1e-8 typedef unsigned long long ULL; using namespace std; int n; int main() { int t; cin >> t; while (t--) { cin >> n; int cnt = 0; while (n != 0) { if (n % 2 == 0)n /= 2; else { n--; cnt++; } } cout << cnt << endl; } //system("pause"); }总结: 水题.