简单题,不知道为啥模拟赛一车人做这个做了 3h 左右,反正我 30min 做完了,甚至是第一遍把题读成 次操作能过于是写了一个错误代码的情况下。
考虑我们先对 ,做一遍操作,让 。
那么我们现在要让 增加 ,考虑递归构造,假设我们现在要把第 个位置增加 :
- 若 ,直接在 做 次操作。
- 否则,如果 ,在 做一次操作,。
- 递归的将 个位置增加 。
- 在 做两次操作。
次数跑下来平均在 次左右,最坏次数应当为 ,大概 次,于是就做完了。
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a[105];
vector<int> res;
void calc(int x){
res.push_back(x);
a[x]+=a[x+1];
}
void slv(int n,int x){
if(x<=2){
for(int i=1;i<=x;i++) calc(n);
return;
}
if(x&1) calc(n);
slv(n+1,x/2-1);
calc(n),calc(n);
}
void solve(){
res.clear();
cin>>n;
for(int i=1;i<=100;i++) a[i]=0;
a[100]=1;
for(int i=99;i>=1;i--) calc(i);
slv(1,n-1);
cout<<res.size()<<endl;
for(int i:res) cout<<i<<' ';
cout<<endl;
}
signed main(){
// freopen("construct.in","r",stdin);
// freopen("construct.out","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);
int T,_;cin>>T>>_;while(T--) solve();
return 0;
}