比赛 位运算及及其应用题单 评测结果 AAAAAAAAAT
题目名称 A类B类数 最终得分 90
用户昵称 IMZ 运行时间 2.542 s
代码语言 C++ 内存使用 3.51 MiB
提交时间 2025-01-25 15:28:27
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int a=0,b=0;
bool solve(int x){
    a=0,b=0;
    for(;x;x>>=1){
        if((x&1)==1){
            a++;
        }
        else{
            b++;
        }
    }
    if(a>b){
        return 1;
    }
    return 0;
}
int main(){
    freopen("abnum.in","r",stdin);
    freopen("abnum.out","w",stdout);
    int n;
    scanf("%d",&n);
    int ret1=0,ret2=0;
    for(int i=1;i<=n;i++){
        if(solve(i)==1){
            ret1++;
        }
        else{
            ret2++;
        }
    }
    printf("%d %d",ret1,ret2);
    return 0;
}