xdoj Problem 1023 - Data Statistic

简介:

Problem 1023 - Data Statistic

 

       一个很典型的数位统计,统计0-n中p进制下字符k出现了多少次。

       最不会的题目就是数位统计了,每次写这种题都写得头晕。今天先是想学学数位dp的,但学了一下午还是不会……还是太弱了。

        直到晚上还是用普通的统计方法写了,这题有一个奸诈之处就是k可能大于p……

 

       真的弱爆了,现在啥都不会了,继续好好刷题,希望元旦之前可以推进到dp,每天至少一题

 

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <math.h>
using namespace std;
int main()
{
    long long n;
    int base,A,now;
    char aim;
    long long b[65]={0,1},c[65]={0,1},i;
    while(~scanf("%lld%d%*c%c",&n,&base,&aim))
    {
        if(aim>='0'&&aim<='9')A=aim-'0';
        else if(aim>='A'&&aim<='Z')A=aim-'A'+10;
        else A=aim-'a'+36;

        if(A==0&&n==0){printf("1\n");continue;}
        if(A>=base){printf("0\n");continue;}

        long long level,ans=0,now;
        level=(1.0*log(n)/log(base))+1.0;
        for(i=2;i<=level;i++)
        {
            b[i]=base*b[i-1];
            c[i]=b[i]*i;
        }
        for(i=level;i>0;i--)
        {
            now=n/b[i];n%=b[i];
            ans+=now*c[i-1];
            if(now>A)ans+=b[i];
            if(now==A)ans+=n+1;
        }
        if(A==0)
        {
            for(i=level;i>0;i--) ans-=b[i];
            ans++;
        }
        printf("%lld\n",ans);
    }
}


 

目录
相关文章
|
前端开发 安全
| ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lin
| ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lin
792 0
成功解决Problem while trying to mount target
成功解决Problem while trying to mount target
|
数据可视化 数据挖掘 开发者
Data-Basic Statistical Descriptions of Data| 学习笔记
快速学习 Data-Basic Statistical Descriptions of Data。
Data-Basic Statistical Descriptions of Data| 学习笔记
|
程序员 PHP 区块链
Error: the tx doesn't have the correct nonce.TestRPC/Ganache无法获取nonce
做一个truffle相关的项目,每次尝试创建交易时,总会有以下的一个错误提示: the tx doesn’t have the correct nonce 完整的一般是这样: Error: the tx doesn't have the correct nonce.
2652 0
lecture 2.2 problem set 1 and 2
1 COUNTING VOWELS   (10/10 分数) Assume s is a string of lower case characters.
1045 0
lecture 3.2 problem set 3
"Radioactive decay" is the process by which an unstable atom loses energy and emits ionizing particles - what is commonly refered to as radiation.
1141 0
|
SQL Oracle 关系型数据库
Data Migration Pre-Check Failures and Solutions
Alibaba Cloud Data Transmission Service supports data transmission between database-centered structured storage products.
2575 0