sdut 2609 A-Number and B-Number (数位dp,二分答案)

题意:

求第n个Bnumber。

题解:

我们可以二分枚举答案,判断是否满足条件,通过二分不断往正确解缩进。那么问题就变成求n以内的数包含了多少Bnumber,这个很明显是用数位dp求解,先求出Anumber的个数,然后减去不满足的数就是Bnumber的个数,处理有一点小技巧。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#define B(x) (1<<(x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void cmax(int& a,int b){ if(b>a)a=b; }
void cmin(int& a,int b){ if(ba)a=b; }
void cmin(ll& a,ll b){ if(b>1;
        ull t=fcnt(mid);
        if(t>=n)
            r=mid-1;
        else
            l=mid+1;
    }
    return l;
}

int main(){
    //freopen("E:\\read.txt","r",stdin);
    ull n;
    memset(vis,false,sizeof vis);
    while(scanf("%llu",&n)!=EOF){
        cout<




你可能感兴趣的:(动态规划—数位dp,动态规划)