Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined) C. Subsequence Counting

  • 题目链接: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);
    }
    //test();
}

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()]);
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值