ural1057Amount of Degrees
Description
18 = 2 4+2 1,
20 = 2 4+2 2.
Input
Output
Sample Input
| input | output |
|---|---|
15 20 |
3 |
Source
所求的数为互不相等的幂之和,亦即其B进制表示的各位数字都只能是0和1。 因此,我们只需讨论二进制的情况,其他进制都可以转化为二进制求解。
设f[i,j]代表i位二进制数中恰好有j个1的数的个数。其实这个就是组合数。
最后的问题就是如何处理非二进制。 对于询问n,我们需要求出不超过n的最大B进制表示只含0、1的数:找到n的左起第一位非0、1的数位,将它变为1,并将右面所有数位设为1。 将得到的B进制表示视为二进制进行询问即可。 如n = (10204)9进制 n = (10111)2进制
code:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
char ch;
bool ok;
void read(int &x){
for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
const int maxl=;
int l,r,k,b,c[maxl][maxl],len,a[maxl],ans;
void init(){
for (int i=;i<=;i++) c[i][]=;
for (int i=;i<=;i++) for (int j=;j<=i;j++) c[i][j]=c[i-][j-]+c[i-][j];
}
int calc(int n){
int t=n,len=,res=,ans=;
memset(a,,sizeof(a));
while (t) a[++len]=t%b,t/=b;
for (int i=len;i;i--) if (a[i]!=&&a[i]!=){
for (;i;i--) a[i]=;
break;
}
for (int i=len;i;i--) if (a[i]) ans+=c[i-][k-res],res++;
return ans;
}
int main(){
init();
read(l),read(r),read(k),read(b);
printf("%d\n",calc(r+)-calc(l));
return ;
}
ural1057Amount of Degrees的更多相关文章
- [TimusOJ1057]Amount of Degrees
[TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...
- AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...
- <poj - 2139> Six Degrees of Cowvin Bacon 最短路径问题 the cow have been making movies
本题链接:http://poj.org/problem?id=2139 Description: The cows have been making movies lately, so the ...
- Economics degrees
Economics degrees Name game"> 经济学学位"> 名称痕戏 Luring students with a new label 新瓶旧酒吸引学生 ...
- 一本通1585【例 1】Amount of Degrees
1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...
- opencv: Rotate image by 90, 180 or 270 degrees
opencv2: void rotate_cw(const cv::Mat& image, cv::Mat& dest, int degrees) { ) { : dest = ima ...
- POJ2139--Six Degrees of Cowvin Bacon(最简单Floyd)
The cows have been making movies lately, so they are ready to play a variant of the famous game &quo ...
- 树形DP ---- Codeforces Global Round 2 F. Niyaz and Small Degrees引发的一场血案
Aspirations:没有结果,没有成绩,acm是否有意义?它最大的意义就是让我培养快速理解和应用一个个未知知识点的能力. ————————————————————————————————————— ...
- POJ 2139 Six Degrees of Cowvin Bacon (floyd)
Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Ja ...
随机推荐
- dvwa+xampp搭建显示乱码的问题:解决办法
如图,dvwa显示乱码,解决办法有两个:
- Ehcache简单说明及使用
EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider. Ehcache是一种广泛使用的开源Java分布式缓存.主要面向通用缓存 ...
- (二)windows下安装PHPCMS V9
一.准备工作 搭建环境 :参考:Windows下搭建PHP开发环境及相关注意事项 PHPCMS V9 :下载适合自己 PHPCMS V9 版本到本地或服务器,下载地址:http://www.phpcm ...
- win10亮度不能调节的解决方法
如果大家遇到Win10屏幕亮度调不了,该如何解决呢?以下是电脑百事网小编亲测比较有用的几种方法,希望能够帮助大家. 修改注册表解决Win10屏幕亮度无法调节 1.首先使用 Win+R 组合快捷键打开W ...
- request和response的中文乱码问题
request乱码指的是:浏览器向服务器发送的请求参数中包含中文字符,服务器获取到的请求参数的值是乱码: response乱码指的是:服务器向浏览器发送的数据包含中文字符,浏览器中显示的是乱码: ...
- C 语言中 typeof keyword简单介绍
原文:http://hi.baidu.com/leowang715/blog/item/b0b96d6f972e7dd080cb4a06.html typeofkeyword是C语言中的一个新扩展.仅 ...
- 模拟dispatch_once
dispatch_once dispatch_once可以保证一段代码只被执行一次,因此出现之后使用最多的场景就是实现单例.本文来模拟实现dispatch_once的功能. 模拟dispatch_ ...
- async 与 await异步编程活用基础
[本文转自:http://www.cnblogs.com/x-xk/archive/2013/06/05/3118005.html 作者:肅] 好久没写博客了,时隔5个月,奉上一篇精心准备的文章,希 ...
- Java基础知识强化之集合框架笔记38:Set集合之Set集合概述和特点
1. Set集合概述和特点 Collection |--List 有序(存储顺序和取出顺序一致),可重复 |--Se ...
- 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之一
/** ****************************************************************************** * @author 暴走的小 ...