- 题目链接:http://codeforces.com/contest/960/problem/C
- 题意:给你两个整数X,d, 找出一个数组满足以下条件:
- 除去Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ d 的子序列后还剩x个子序列
- 算法:暴力
- 思路:把数组元素个数对应的子序列个数列出,会发现:子序列个数=pre+2^(n-1);n为数组元素个数,pre为n-1时的子序列个数,把最接近x且小于x的子序列个数用upperbound算出(ind),然后将输出ind 个tot。将x赋值为剩余的子序列个数(left),重复以上步骤,x=0。
- 然后你会发现其实对于数据范围内的X,d都有对应的子序列。
- 坑点:这个数组的元素可以相同的
#include <bits/stdc++.h>
#define pi acos(-1)
#define fastcin ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL ll_INF = 0x3f3f3f3f3f3f3f3f;
const int maxn =10000 + 10;
const LL mod = 1e9+7;
vector<LL> vec, ans;
void test()
{
for(int i=1; i<vec.size(); i++){
cout << vec[i]-vec[i-1] << " " ;
}
puts("");
}
void init()
{
vec.clear();
LL pre =0;
for(LL i=1; i<=62 && pre<=1e9; i++){
pre = pre+(1<<(i-1));
vec.push_back(pre);
}
}
int main()
{
init();
LL x, d;
scanf("%I64d%I64d", &x, &d);
LL tot=1;
while(x>=1){
LL ind = (upper_bound(vec.begin(), vec.end(), x)-vec.begin());
LL left = x-vec[ind-1];
for(LL i=tot; i<=tot+ind-1; i++){
ans.push_back(tot);
}
tot = ans.back()+d;
x = left;
}
printf("%d\n", ans.size());
for(int i=0; i<ans.size(); i++){
printf("%I64d%c", ans[i], " \n"[i==ans.size()]);
}
}