看了题解要分治,一开始打的代码有bug还不清楚什么情况

#include <cstdio>
#include <algorithm>
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%lld", &x)
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)
#define pr1(x) printf("Case %d: ", x)
#define pn1(x) printf("Case %d:\n", x)
#define pr2(x) printf("Case #%d: ", x)
#define pn2(x) printf("Case #%d:\n", x)
#define lowbit(x) (x & (-x))

typedef unsigned long long ull;
const LL N = 1e4 + 1;
LL m, a[N], cnt;

int main()
{
    scan(m);
    while(m>0){
        a[cnt++]=(m+1)>>1;
        m>>=1;
    }
    sort(a,a+cnt);
    printf("%lld\n",cnt);
    f(i,0,cnt-1)printf("%lld ",a[i]);
    return 0;
}
此文章已被阅读次数:正在加载...更新于