跳到正文

个人记录

TmpCode

guoguo160约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>

#define int long long

using namespace std;

int t;
int n;
int Binary[10000000];
int cnt;

signed main() {
	Binary[0]=1;
	for(int i=1;(1ll<<i)<=1e18;++i) {
		Binary[i]=Binary[i-1]*2;
		cnt++;
	}
	cin >> t;
	while (t--) {
		priority_queue<int> q;
		cin >> n;
		int cn=n;
		for(int i=cnt;i>=0;--i) {
			while(cn>=Binary[i]) {
				q.push(Binary[i]);
				cn-=Binary[i];
			}
		}
		while((1ll<<((int)__lg(q.size()))!=q.size())) {
			int t=q.top();
			q.push(t/2);
			q.push(t/2);
		}
		priority_queue<int,vector<int>,greater<int> > p;
		while(!q.empty()) {
			p.push(q.top());
			q.pop();
		}
		while(!p.empty()) {
			cout<<p.top()<<" ";
			p.pop();
		}
		cout<<"\n";
	}
	return 0;
}
原文