SNIBB

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1485    Accepted Submission(s): 435

Problem Description
  As we know, some numbers have interesting property. For example, any even number has the property that could be divided by 2. However, this is too simple. 
  One day our small HH finds some more interesting property of some numbers. He names it the “Special Numbers In Base B” (SNIBB). Small HH is very good at math, so he considers the numbers in Base B. In Base B, we could express any decimal numbers. Let’s define an expression which describe a number’s “SNIBB value”.(Note that all the “SNIBB value” is in Base 10)
  
    Here N is a non-negative integer; B is the value of Base.
  For example, the “SNIBB value” of “1023” in Base “2” is exactly:10
(As we know (1111111111)2=(1023)(10))
  Now it is not so difficult to calculate the “SNIBB value” of the given N and B.
But small HH thinks that must be tedious if we just calculate it. So small HH give us some challenge. He would like to tell you B, the “SNIBB value” of N , and he wants you to do two kinds of operation:
1.  What is the number of numbers (whose “SNIBB value” is exactly M) in the range [A,B];
2.  What it the k-th number whose “SNIBB value” is exactly M in the range [A,B]; (note that the first one is 1-th but not 0-th)

Here M is given.

 
Input
  There are no more than 30 cases.
  For each case, there is one integer Q,which indicates the mode of operation;
  If Q=1 then follows four integers X,Y,B,M, indicating the number is between X and Y, the value of base and the “SNIBB value”.
(0<=X,Y<=2000000000,2<=B<=64,0<=M<=300)
  If Q=2 then follows five integers X,Y,B,M,K, the first four integer has the same meaning as above, K indicates small HH want to know the k-th number whose “SNIBB value” is exactly M.
(1<=K<=1000000000)
 
Output
  Output contains two lines for each cases.
  The first line is the case number, the format is exactly “Case x:”, here x stands for the case index (start from 1.).
  Then follows the answer.
  If Q=2 and there is no such number in the range, just output “Could not find the Number!” (without quote!) in a single line.
 
Sample Input
1 0 10 10 3
2 0 10 10 1 2
1 0 10 2 1
 
Sample Output
Case 1:
1
Case 2:
10
Case 3:
4

Hint

In case 1, the number in the range [0,10] whose “SNIBB value” is exactly 3 is 3(in Base 10);
In case 2, the numbers in the range [0,10] whose “SNIBB value” is exactly 1 are 1 and 10; Of course the 2-th number is 10.
In case 3, the number in the range [0,10] whose “SNIBB value” is exactly 1 is 1,10,100,1000(in Base 2);

 
Author
AekdyCoin
 
Source
题意:
求区间内的数在b进制下个位数的和是m的数的个数
求区间内第k个在b进制下个位数的和是m的数
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int bit[];
ll f[][];
ll dfs(int pos,int m,bool limit,int b)
{
if(pos==) return m==;
if(m<) return ;
if(!limit&&f[pos][m]!=-) return f[pos][m];
int max_b=(limit?bit[pos]:b-);
ll ans=;
for(int i=;i<=max_b;i++){
ans+=dfs(pos-,m-i,limit&&(i==max_b),b);
}
if(!limit) f[pos][m]=ans;
return ans;
}
ll solve(ll x,int b,int m)
{
if(x<) return ;
int pos=;
while(x){
bit[++pos]=x%b;
x/=b;
}
return dfs(pos,m,,b);
}
int main()
{
int p,b,m,cas=;
ll X,Y,k;
while(scanf("%d",&p)==){
printf("Case %d:\n",++cas);
memset(f,-,sizeof(f));
if(p==){
scanf("%lld%lld%d%d",&X,&Y,&b,&m);
if(X>Y) swap(X,Y);
printf("%lld\n",solve(Y,b,m)-solve(X-,b,m));
}else{
scanf("%lld%lld%d%d%lld",&X,&Y,&b,&m,&k);
if(X>Y) swap(X,Y);
ll tmp1=solve(Y,b,m),tmp2=solve(X-,b,m);
if(k>tmp1-tmp2) puts("Could not find the Number!");
else{
ll l=X,r=Y,ans;
while(l<=r){
ll mid=(l+r)>>;
ll tmp=solve(mid,b,m);
if(tmp-tmp2>=k) { ans=mid;r=mid-; }
else l=mid+;
}
printf("%lld\n",ans);
}
}
}
return ;
}

HDU 3271 数位dp+二分的更多相关文章

  1. HDU 3943 数位dp+二分

    K-th Nya Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) ...

  2. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

  3. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. poj3208 Apocalypse Someday 数位dp+二分 求第K(K <= 5*107)个有连续3个6的数。

    /** 题目:poj3208 Apocalypse Someday 链接:http://poj.org/problem?id=3208 题意:求第K(K <= 5*107)个有连续3个6的数. ...

  5. hihocoder #1301 : 筑地市场 数位dp+二分

    题目链接: http://hihocoder.com/problemset/problem/1301?sid=804672 题解: 二分答案,每次判断用数位dp做. #include<iostr ...

  6. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  7. UPC 2223: A-Number and B-Number(数位DP+二分)

    积累点: 1: (l&r)+((l^r)>>) == (l+r)/2 2: 注意判断现在是否有限制.当枚举下一个量时,是(isQuery && j==end),不要 ...

  8. CodeChef FAVNUM FavouriteNumbers(AC自动机+数位dp+二分答案)

    All submissions for this problem are available. Chef likes numbers and number theory, we all know th ...

  9. hdu:2089 ( 数位dp入门+模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...

随机推荐

  1. 将本地开发完的SDK代码上传到SVN上面:an error occurred while contacting the repository The server may be unreachable or the URL may be incorrect

    将本地开发完的SDK代码上传到SVN上面:an error occurred while contacting the repository  The server may be unreachabl ...

  2. “Hello World!”Final发布文案加美工

    文案: 大家好,我们是“Hello World!”团队,本次我将向大家简要介绍一下空天猎的final发布,在空天猎final发布中,我主要从以下两个方面向大家进行介绍,第一个方面是增加了敌方的boss ...

  3. 2017年软件工程作业-“Hello World!”团队互评beta版本

    A.欢迎来怼——博客园安卓APP(测评人:刘淑霞) 博客地址:http://www.cnblogs.com/liusx0303/p/7905928.html B.Thunder——爱阅app(测评人: ...

  4. 冲刺One之站立会议7 /2015-5-20

    2015-5-20 在登陆成功之后要实现的是聊天界面的交互过程,不同的IP进行信息和数据的传递,这方面我们上学期Java实验里面有过相关的内容,我们把它拿过来改了一下格式,试着看能不能成功,目前还没实 ...

  5. Java每日学习笔记1

    单选按钮 JRadioButton radioButton1 = new JRadioButton("Java");// 创建单选按钮 contentPane.add(radioB ...

  6. 2018软工实践—Beta冲刺(3)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Beta 冲鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 软件接口编写修正 自动化测试脚本编写 技术文稿更新 展示GitHub当 ...

  7. BNUOJ 52305 Around the World 树形dp

    题目链接: https://www.bnuoj.com/v3/problem_show.php?pid=52305 Around the World Time Limit: 20000msMemory ...

  8. vue 里面的watch 选项详解

    早就想好好写写这个watch了,一直顾不上,因为想深刻的记录一下,其实这些东西只要是好好看看官网的说明,都在里面呢. 虽然计算属性在大多数情况下更合适,但有时也需要一个自定义的侦听器.这就是为什么 V ...

  9. /etc/tolmcat/Server.xml 实例说明

      # 这是service类 <Service name="Catalina">   # 这是http连接器,响应用户请求 <Connector port=&qu ...

  10. [BUAA_SE_2017]代码复审-Week2

    代码复审 CheckList 1.概要部分 代码能符合需求和规格说明么? 符合,经过-c及-s合法参数测试,程序均能生成.求解相应数独. 代码设计是否有周全的考虑? 对于非法输入,程序处理不够周全. ...