#include <iostream>
#include <string>
using namespace std; int f[][];
void init(){
f[][] =;
for(int i=;i<=;i++){
f[i][] = f[i-][];
for(int j=;j<=i;j++)
f[i][j] = f[i-][j]+f[i-][j-];
}
} int change(int x,int b){
string s;
while(x){
s = (char)(x%b+'')+s;
x = x/b;
}
for(int i=;i<s.size();i++)
if(s[i]>''){
for(int j=i;j<s.size();j++)
s[j] = '';
break;
}
x =;
for(int i=;i<s.size();i++){
x = x|((s[s.size()--i]-'')<<i);
}
return x;
} int cal(int x,int k){
int tot =,ans =;
for(int i=;i>;i--){
if(x&(<<i)){
tot++;
if(tot>k) break;
x = x^(<<i);
}
if((<<(i-))<=x){
ans += f[i-][k-tot];
}
}
if(tot + x==k) ans++;
return ans;
} int main()
{
init();
int x,y;
int k,b;
cin>>x>>y>>k>>b;
x= change(x,b);
y = change(y,b);
int resx = cal(x-,k);
int resy = cal(y,k);
cout<<resy-resx<<endl;
return ;
}

ural1057 Amount of degrees 位数统计的更多相关文章

  1. [ACM] ural 1057 Amount of degrees (数位统计)

    1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the am ...

  2. [ural1057][Amount of Degrees] (数位dp+进制模型)

    Discription Create a code to determine the amount of integers, lying in the set [X; Y] and being a s ...

  3. Ural1057. Amount of Degrees 题解 数位DP

    题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...

  4. Ural1057 - Amount of Degrees(数位DP)

    题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...

  5. ural1057 Amount of Degrees

    链接 这题有一点小坑点 就是AX^B  A只能为0或者1  ,剩下的就比较好做的了. #include <iostream> #include<cstdio> #include ...

  6. URAL1057. Amount of Degrees(DP)

    1057 简单的数位DP  刚开始全以2进制来算的 后来发现要找最接近x,y值的那个基于b进制的0,1组合 #include <iostream> #include<cstdio&g ...

  7. 一本通1585【例 1】Amount of Degrees

    1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...

  8. Ural Amount of Degrees(数位dp)

    传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...

  9. [TimusOJ1057]Amount of Degrees

    [TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...

随机推荐

  1. ECSHOP 模版文件里的编辑区域

    Ecshop 中的模板能够有可编辑区域,在模板中是通过 <!-- TemplateBeginEditable name="左边区域" --> <!-- Templ ...

  2. org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x0) was found in the CDATA sectio

    偶尔有一次beyond compare比较部署文件时,发现有一个JSP文件结尾的地方有一大堆空白的二进制符号,当时没有管,就覆盖上去了. =================背景分割线========= ...

  3. C#时间格式之GMT时间的格式

    GMT:格林尼标准时间  北京时间=GMT时间+8小时 DataTime nowDate = DataTime.Now; nowDate.toString("r");    效果为 ...

  4. CSS中的 REM PX EM

    px像素(Pixel).相对长度单位.像素px是相对于显示器屏幕分辨率而言的 em是相对长度单位.相对于当前对象内文本的字体尺寸.如当前对行内文本的字体尺寸未被人为设置,则相对于浏览器的默认字体尺寸. ...

  5. phoenegap3.5 采坑

    上周5晚上在家看Node.js视频的时候,老大来一条短信让研究下 phoengap打包一个web网站. 遂 陷入了phonegap的深渊中. phoengap很早开始使用 cli模式安装开发环境 ,借 ...

  6. js生成验证码并且判断

       <style type="text/css">        .code        {            font-family: Arial;      ...

  7. HOJ1008

    #include<iostream> using namespace std; int main(){ ; ; ){ ; ; numTemp = N; ) && count ...

  8. Scala学习之for 循环和 yield 的例子

    for循环中的 yield 会把当前的元素记下来,保存在集合中,循环结束后将返回该集合.Scala中for循环是有返回值的.如果被循环的是Map,返回的就是Map,被循环的是List,返回的就是Lis ...

  9. JavaEE学习之设计模式

    转自:http://mp.weixin.qq.com/s?__biz=MjM5OTMxMzA4NQ==&mid=221913387&idx=2&sn=d5d006300722f ...

  10. vi、vim 配置上下左右方向键和删除键

    vi.vim 配置上下左右方向键和删除键 " An example for a vimrc file. " " Maintainer: Bram Moolenaar &l ...