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);
    }
}


 

目录
相关文章
|
6月前
ERROR: No matching distribution found for tb-nightly
ERROR: No matching distribution found for tb-nightly
204 1
|
6月前
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
119 5
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]
|
数据可视化 数据挖掘 开发者
Data-Basic Statistical Descriptions of Data| 学习笔记
快速学习 Data-Basic Statistical Descriptions of Data。
Data-Basic Statistical Descriptions of Data| 学习笔记
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
108 0
Data Structures and Algorithms (English) - 6-14 Count Connected Components(20 分)
Data Structures and Algorithms (English) - 6-14 Count Connected Components(20 分)
139 0
成功解决 ValueError: feature_names mismatch training data did not have the following fields
成功解决 ValueError: feature_names mismatch training data did not have the following fields
|
SQL 关系型数据库 RDS
9 Easy Steps for Successful Data Migration
Migrate your database without service interruptions with Alibaba Cloud Data Transmission Service
1984 0
9 Easy Steps for Successful Data Migration
|
Java Apache
Failed to place enough replicas
如果DataNode的dfs.datanode.data.dir全配置成SSD类型,则执行“hdfs dfs -put /etc/hosts hdfs:///tmp/”时会报如下错误: 2017-05-04 16:08:22,545 WARN org.
3296 0