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. 微信小程序开发调试技巧

    1.  查看线上小程序console a.  先打开开发小程序console b.  再打开线上小程序,此时可以查看console

  2. Windows搭建python开发环境

    python你不去认识它,可能没什么,一旦你认识了它,你就会爱上它 基本概念Python(英语发音:/ˈpaɪθən/), 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum ...

  3. ajax 异步刷新

    第一种方法,ajax实现:当然,ajax使用起来确实很简单就可以实现,但是里面的很多知识还是比较有点深的.我之前做页面时间自动刷新的功能就是用的ajax.完整代码是:1.getTime.php: 复制 ...

  4. Eclipse各版本分析比较

    Eclipse最初是由IBM公司开发的替代商业软件Visual Age for Java的下一代IDE开发环境,2001年11月贡献给开源社区,现在它由非营利软件供应商联盟Eclipse基金会. Ec ...

  5. Beta发布--PSP DAILY软件功能说明书2.0

    一.开发背景 你在完成了一周的软件工程作业后,需要提交一个PSP图表,里面有4项,如下所示: 1.本周PSP表格,包含每项任务的开始.中断.结束.最终时间,格式如下: 2.本周进度条,包含从开始到现在 ...

  6. TeamWork#2,Week 2,We are sixsix!

    We are sixsix! (从左至右依次是:郝倩.张志浩.高雅智[高哥].牛强.张明培育.彭林江.王卓) 郝倩,来自120617班,我们组7个成员中唯一一个6行政班以外的成员.为了达成组队条件,彭 ...

  7. 课堂alpha发布

    项目组名:奋斗吧兄弟 今天七组对于各自项目现有的成果进行了alpha发布,下面是我的一些感想. 天天向上团队的连连看游戏: 令我印象最深的是天天向上团队的连连看项目,他们目前能展示给我们的是核心的连连 ...

  8. koa中接收前台传递的各种数据类型的方式

    标签(空格分隔): koa 数据类型接收 主要介绍三种会用到的中间件,其实都是自己在开发的过程中踩过的坑 首先介绍koa-body [详情介绍 https://github.com/dlau/koa- ...

  9. exFAT移动硬盘写保护怎么去掉

    cmd命令提示符下运行chkdsk命令: 比如在E盘,则输入的命令如下: E:(冒号不可少,输入后回车) CHKDSK /F /X  (回车) 等命令执行完了,即可去掉exFAT移动硬盘写的保护.

  10. 微信小程序 功能函数 将对象的键添加到数组 (函数深入)

    // 将对象的键添加到数组 var arr = Object.keys(site); //英文 https://developer.mozilla.org/en-US/docs/Web/JavaScr ...