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. 如何用css实现"等高布局"。

    有时候为了让网页实现美观,在不知道高度的情况下,我们要用css实现等高布局效果,传统的方法, 我们可以用javascript实现,但是由于需求决定或者其他的情况下,我们只能用css实现,其方法主要是采 ...

  2. Java实现对象的序列化

    什么是对象的序列化? 序列化:把对象转化成字节序列的过程就是对象的序列化:反序列化:把字节序列转化成对象的过程就是对象的反序列化.单看概念比较抽象,但是看代码就会明白. 对象序列化的用途 1.Java ...

  3. ASP.NET Core 释放 IDisposable 对象的四种方法

    本文翻译自<Four ways to dispose IDisposables in ASP.NET Core>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! IDispos ...

  4. 计算2个时间之间经过多少Ticks

    Ticks是一个周期,存储的是一百纳秒,换算为秒,一千万分之一秒.我们需要计算2个时间之间,经过多少Ticks,可以使用下面的方法来实现,使用2个时间相减. 得到结果为正数,是使用较晚的时间减去较早的 ...

  5. Data Partitioning Guidance

    在很多大规模的解决方案中,数据都是分成单独的分区,可以分别进行管理和访问的.而分割数据的策略必须仔细的斟酌才能够最大限度的提高效益,同时最大限度的减少不利影响.数据的分区可以极大的提升可扩展性,降低争 ...

  6. 【调试技巧】 Fiddler高级用法之url映射请求

    问题场景: 已发布线上APP出现接口错误,如何测试线上APP访问本地请求? 已发布线上H5页面,静态资源或js调试,如何映射本地js? 一般解决方案: 猜测(一般明显问题). 找到原发布包,修改请求资 ...

  7. windows如何查看电脑开关机记录

    如何查看电脑开关机记录 (一)如果你只是想查看一下,从昨天关机到今天开机之间有没有人使用我的计算机,在“开始”菜单的运行”中输入“eventvwr.msc”,或者是按下"开始菜单" ...

  8. Python_每日习题_0001_数字组合

    # Topic: There are four digits: 1, 2, 3 and 4. # How many different three digits can be formed witho ...

  9. Python练习之用户登录-5

    格式化输出 %s %d %% 编码: ascii 只能显示英文,特殊字符,数字. 万国码:unicode 最开始16位,中文不够32位 4个字节. 占用资源多. 升级:utf-8 utf-16 utf ...

  10. 后台跑包方法 断开ssh程序也能继续执行的方法screen命令

    aircrack-ng -w 字典路径 握手包路径 screen -S 001创建会话 screen -ls  列出窗口列表 screen -r 5位数字  进入会话指令 如果会话恢复不了,则是有可能 ...