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. POJ2387(dijkstra堆优化)

    Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much s ...

  2. python3.6.4源码安装

    该脚本适合centos6和ubuntu用,关于debian可以根据脚本中的范例自己添加 微笑哥与你每天进步一点点 #!/bin/bash##Check systemcheck_sys(){ local ...

  3. SkylineGlobe 如何使用二次开发接口创建粒子效果

    SkylineGlobe在6.6版本,ICreator66接口新增加了CreateEffect方法,用来创建粒子效果对象: 以及ITerrainEffect66对象接口,可以灵活设置粒子效果对象的相关 ...

  4. day81

    昨日回顾: 昨日回顾: auth组件: -验证:authenticat(request,username=') -登录:login(request,user) -注销:logout(request), ...

  5. HTTP-从输入url到请求回数据发生了什么

  6. HTML 图片轮播制作工具

    下载地址:http://wowslider.com/download/wowslider-win-setup.zip?utm_source=free_downl_win&utm_medium= ...

  7. redis 配置 架构 基础

    redis 官网  redis.io   io为某国家域名后缀 有redis各种版本. java 版本 又分各种工具 clients 下 RedisClient为图形化管理界面 Jedis 才是jav ...

  8. Spring boot多模块(moudle)中的一个注入错误(Unable to start embedded container; nested exception is org)

    org.springframework.context.ApplicationContextException: Unable to start embedded container; nested ...

  9. 运行supervisord -c /etc/supervisor/supervisord.conf 出错,解决办法

    坑都让我踩了...... 1 supervisord -c /etc/supervisor/supervisord.conf 什么意思? 答:手动启动:supervisord        具体详见 ...

  10. 老生常谈,函数柯里化(curring)

    柯里化这个概念确实晦涩难懂,没有深入思考过的人其实真的很难明白这是一个什么东西.看起来简单.简单到或许只需要一行代码: const curry = fn => (…args) => fn. ...