Description
定義一個序列是好的當且僅當它可以被表示成一個序列複製一倍後拼接,例如:aaaa,abab,abcabc
給定一個n,要求構造一個序列s滿足
- |s|<=200
- s中含有恰好n個好的子序列
- s中的元素∈[1,100]
Solution
一般的構造考慮兩個方向,拆成若干段不干擾然後拼接,或者考慮倍增得到它
可以發現aXaY恰好是XY的兩倍,而aXYa恰好比XY多1,其中a是XY中沒出現過的任意元素
我們利用這個性質就可以logn倍增這個東西了
Code
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
typedef long long LL;
const int N=20005;
int tot;
std:: deque <int> L,R;
void solve(LL n) {
if (n==1) return ;
solve(n/2);
L.push_front(++tot);
R.push_front(tot);
if (n&1) {
L.push_front(++tot);
R.push_back(tot);
}
}
int main(void) {
LL n; scanf("%lld",&n);
solve(n+1);
printf("%d\n", L.size()+R.size());
for (int i=0;i<L.size();++i) printf("%d ", L[i]);
for (int i=0;i<R.size();++i) printf("%d ", R[i]);
puts("");
return 0;
}