最后四个点愣是过不去。。
查看原帖
最后四个点愣是过不去。。
678057
_TeaClaudz_楼主2022/10/23 17:22
#include<iostream>
#include<cmath>
using namespace std;

bool b[101];

int main()
{
    ios::sync_with_stdio(0);
    register int n, p = 1, cnt = 0, cnt2;
    cin >> n;
    if(n % 2 == 1)
    {
        cout << -1;
        return 0;
    }
    while(p << 1 <= n)
    {
        p <<= 1;
        cnt++;
    }
    cnt2 = cnt;
    while(p > 1)
    {
        if(n >= p)
        {
            b[cnt2] = 1;
            n -= p;
        }
        p >>= 1;
        cnt2--;
    }
    for(register int i = cnt; i >= 1; --i)
    {
        if(!b[i]) continue;
        cout << pow(2, i) << ' ';
    }
    return 0;
}
2022/10/23 17:22
加载中...