B. Jamie and Binary Sequence (changed after round)
y最小,字典序最大
先按二进制分解,最大的为2x。如果全都拆成2x-1,拆完之后总个数还比k小,就拆,不然就拆最小的
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define rep(a, b, c) for(int (a)=(b);(a)<=(c);(a)++)
#define per(a, b, c) for(int (a)=(b);(a)>=(c);(a)--)
#define mset(var, val) memset(var,val,sizeof(var))
#define ll long long
#define int ll
#define fi first
#define se second
#define no "No\n"
#define yes "Yes\n"
#define eb emplace_back
#define endl "\n"
#define pii pair<int,int>
#define pll pair<ll,ll>
const int N = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
priority_queue<int>q;
priority_queue<int,vector<int>,greater<int> >p;
map<int,int>mp;
void solve() {
int n,k,mx=-100;
cin>>n>>k;
per(i,62,0){
if(n&(1ll<<i)){
q.push(i);
mp[i]++;
if(mp[i]) mx=max(mx,i);
}
}
if(q.size()>k){
cout<<no;
return;
}
int len=k-q.size();
while(mp[mx]<=len){
int tx=q.top();
len=len-mp[mx];
while(1){
int x=q.top();
if(x!=tx) {
mp[mx-1]=mp[mx-1]+mp[mx]*2;
mp[mx]=0;
mx=mx-1;
break;
}
q.pop();
q.push(x-1);
q.push(x-1);
}
}
while(!q.empty()){
p.push(q.top());
q.pop();
}
for (int i = 0; i < len; ++i) {
int x=p.top();
p.pop();
p.push(x-1);
p.push(x-1);
}
while(!p.empty()){
q.push(p.top());
p.pop();
}
cout<<yes;
while(!q.empty()){
cout<<q.top()<<" ";
q.pop();
}
cout<<endl;
}
signed main() {
IOS;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
标签:11,周赛,const,cout,int,08,var,ll,define
From: https://www.cnblogs.com/ShG-V/p/16879342.html