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. ELF格式文件分析以及运用

    基于本文的一个实践<使用Python分析ELF文件优化Flash和Sram空间的案例>. 1.背景 ELF是Executable and Linkable Format缩写,其官方规范在& ...

  2. 每个大主播都是满屏弹幕,怎么做到的?Python实战无限刷弹幕!

    anmu 是一个开源的直播平台弹幕接口,使用他没什么基础的你也可以轻松的操作各平台弹幕.使用不到三十行代码,你就可以使用Python基于弹幕进一步开发.支持斗鱼.熊猫.战旗.全民.Bilibili多平 ...

  3. Linux安装maven以及配置-Centos7版本

    1.Linux安裝maven 1.如果電腦沒有wget命令的,先使用yum安裝wget命令.eg: yum install wget 2.安裝好后就可以直接使用wget命令去下載maven. 附:打开 ...

  4. CF293B Distinct Paths 搜索

    传送门 首先数据范围很假 当\(N + M - 1 > K\)的时候就无解 所以对于所有要计算的情况,\(N + M \leq 11\) 超级小是吧,考虑搜索 对于每一个格子试填一个数 对于任意 ...

  5. Java 中单引号和双引号的区别

    引自:https://blog.csdn.net/hubianyu/article/details/39700367 单引号引的数据 是char类型的 双引号引的数据 是String类型的char定义 ...

  6. bitset常用用法&&简单题分析

    Preface bitset,还是一个比较好用的STL,可以给一些题目做到神奇的常数优化(\(O(\frac{原来的复杂度}{机器的位数(32位or64位)})\)) 关于一些具体的函数等内容可以参考 ...

  7. Flutter - 创建自适应的Android app 图标

    上一篇文章说到  Flutter - 自动生成Android & iOS图标 通过flutter_launcher_icons 可以一键生成所有的Icon 到此基本什么问题也没有,如果你用io ...

  8. 个人java框架 技术分析

    1.框架选型 spring-boot https://github.com/JeffLi1993/springboot-learning-example https://mp.weixin.qq.co ...

  9. React.js 开发参见问题 Q&A

    文章中我整理了 React.js 开发过程中一些参见问题的解答汇总,供大家参考. 1. 一些课程资源 课程完整的思维导图请查考文章:React.js 入门与实战课程思维导图,我使用的思维导图软件是 M ...

  10. [朴孝敏][Ooh La La]

    歌词来源:http://music.163.com/#/song?id=484058960 作曲 : Damon Sharpe/Jimmy Burney/Adam Kapit [作曲 : Damon ...