vc+24KOs0KHHvyDPo837xOPE3LDvy/u1w7W9w9zUv6OsusPU2rPJvKi5q7K81q7HsL2rs8m8qLjEuf3AtKGjPC9wPgo8cD4KPC9wPgo8cD4KyuTI68PoyvajujwvcD4KPHA+CsrkyOvTybbg1+nK/b7dubmzyaOsw7/X6cr9vt212tK70NDOqtK7uPbK/SBuKDE8PW48PTEwXjUpo6yx7cq+yv21xMr9wb+jrLXatv7Q0CBuILj21fvK/bHtyr7OxLz+1tC1xMO/uPbK/SgxPD3Dv7j2yv08PTEwXjkpoaPS1M7EvP694c6yoaM8L3A+CjxwPgrK5LP2w+jK9qO6PC9wPgo8cD4KttTT2sO/1+nK/b7dyuSz9tK70NCjrM/IyuSz9sr9vt3X6cr9o6zU2crks/a2/r341sbW0LqsIDEg1+7J2bXEyv2jrMjnufvT0LbguPbK/bf7us/M9bz+o6zK5LP21+7QobXExMe49qGjPC9wPgo8cD4KPGJyPgo8L3A+Cjxicj4KPHA+CjwvcD4KCgoKCrTwzOLLtcP3Cgo8cD4KyuTI69H5wP2jujwvcD4KPHA+CjU8L3A+CjxwPgozIDIgNCA1IDY8L3A+CjxwPgrK5LP20fnA/aO6PC9wPgo8cD4KQ2FzZSAxOiAyPC9wPgoKCjxoMiBjbGFzcz0="ans_tip">
解題思路:利用這個函數就可以計算一個數的二進制有多少個1:
int totalOne(int x){
int count = 0;
while(x){
x = x & ( x - 1 );
count++;
}
return count;
}
所以我們只需遍歷一邊即可;
#include
using namespace std;
int totalOne(int x){
int count = 0;
while(x){
x = x & ( x - 1 );
count++;
}
return count;
}
int main(){
int n,a,step=1;
while (cin>>n){
int max=0,num=0,min=0xffffff;
for (int i=0;i>a;
num=totalOne(a);
if (numa)
max=a;
}
cout<<"Case "<