1585: 【例 1】Amount of Degrees

时间限制: 1000 ms         内存限制: 524288 KB

题目描述

原题来自:NEERC 2000 Central Subregional,题面详见 Ural 1057

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

17=2^4+2^0

18=2^4+2^1

20=2^4+2^2

输入格式

第一行包含两个整数 X 和 Y,接下来两行包含整数 K 和 B。

输出格式

只包含一个整数,表示满足条件的数的个数。

样例

样例输入

15 20
2
2

样例输出

3

数据范围与提示

对于全部数据, 1≤X≤Y≤2^31−1,1≤K≤20,2≤B≤10。

sol:把一个数想象成一个有B进制表示但只有(0,1)组成的数,统计的时候把n拆成B进制,用组合数计算一下,如果那位数字>1的话就退出,如果=1的话就对于那位填(0,1)讨论一下

#include <bits/stdc++.h>
using namespace std;
inline int read()
{
int s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-');
ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^);
ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(int x)
{
if(x<)
{
putchar('-');
x=-x;
}
if(x<)
{
putchar(x+'');
return;
}
write(x/);
putchar((x%)+'');
return;
}
inline void writeln(int x)
{
write(x);
putchar('\n');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) writeln(x)
int l,r,k,B;
int C[][];
inline void Init()
{
int i,j;
for(i=;i<=;i++)
{
C[i][]=;
for(j=;j<=i;j++)
{
C[i][j]=C[i-][j]+C[i-][j-];
}
}
return;
}
/*
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
*/
inline int Solve(int n)
{
int i,Len=,ans=,Now_k=k;
int a[];
while(n)
{
a[++Len]=n%B;
n/=B;
}
for(i=Len;i>=;i--)
{
if(a[i]==)
{
ans+=C[i-][Now_k];
Now_k--;
}
else if(a[i]>)
{
ans+=C[i][Now_k];
break;
}
if(Now_k<)return ans;
}
if(Now_k==) ans++;
return ans;
}
int main()
{
int i;
Init();
R(l); R(r); R(k); R(B);
Wl(Solve(r)-Solve(l-));
return ;
}
/*
input
15 20
2
2
output
3
*/

一本通1585【例 1】Amount of Degrees的更多相关文章

  1. 【算法•日更•第十二期】信息奥赛一本通1585:【例 1】Amount of Degrees题解

    废话不多说,直接上题: 1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB提交数: 130     通过数: 68 [ ...

  2. [TimusOJ1057]Amount of Degrees

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

  3. Timus Online Judge 1057. Amount of Degrees(数位dp)

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

  4. [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 ...

  5. Ural Amount of Degrees(数位dp)

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

  6. [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 ...

  7. URAL 1057 Amount of Degrees (数位dp)

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

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

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

  9. 2018.09.07 Amount of degrees(数位dp)

    描述 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和. 例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 17 = 24+20, ...

随机推荐

  1. Linux kernel Programming - Allocating Memory

    kmalloc #include <linux/slab.h> void *kmalloc(size_t size,int flags); void kfree(void *addr); ...

  2. 工具 Sublime日志染色

    工欲善其事,必先利其器. Preferences -> Browse Packages...

  3. BSGS-Junior·大步小步算法

    本文原载于:http://www.orchidany.cf/2019/02/06/BSGS-junior/#more \(\rm{0x01}\) \(\mathcal{Preface}\) \(\rm ...

  4. Zephyr学习专题

    1 前言 本来想学习Zyphyr的Power Management,但是看着看着就被带进去了. 你看功耗,里面的suspend涉及到时间补偿相关的吧,然后就涉及到了Kernel Clocks/Time ...

  5. 推荐几本对于Python初学者比较好的书籍(内含PDF)

    我们提供一个初学者最好的Python书籍列表.Python是一个初级程序员可以学习编程的最友好语言之一.为了帮助您开始使用Python编程,我们分享此列表.泡一杯茶,选一本书阅读,开始使用Python ...

  6. 浅谈传感器常用Delta-SigmaADC

    过采样ADC,或噪声整形ADC,也叫Delta-Sigma ADC.名字很多,基本上都由求差电路,积分求和电路组成调制器,后续由数字滤波器获得Nbit数字输出.不管怎样,数学上的除法能够让你理解这类A ...

  7. 读取Excel的记录并导入SQL数据库

    准备一下,近段时间,需要把Excel的数据导入数据库中. 引用命名空间: using System.Configuration; using System.Data; using System.Dat ...

  8. Angularjs演示Service功能

    在angularjs中,我们可以自定义自己的service.可以说得是自定义的方法,函数. 下面我们一步一步来演示吧:首先为angularjs定义一个app: var demoApp = angula ...

  9. chrome浏览器直接打印 - z

    在地址栏敲: about:flags ,打开设置界面:停用:Enable Print Preview Registration PromosChrome快捷方式增加:--kiosk-printing这 ...

  10. nginx 安装问题

    yum -y install  xxx pcre-devel  openssl-devel   zlib-devel  这个三个包需要 有时候,我们需要单独安装nginx,来处理大量的下载请求.单独在 ...