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 ...
随机推荐
- HTML5 Security Cheatsheet使用说明
1.URL: https://html5sec.org/ 2.通过点击如图button(也可点击其他:xss firefox)那行的button可以搜索所有button的Cheatsheet,查看都有 ...
- tl;drLegal ——开源软件license的搜索引擎
TLDRLegal - Open Source Licenses Explained in Plain English可以很方便查询各个开源license的总结(能做什么,不能做什么),还能比较不同的 ...
- Latex插入图片 分类: LaTex 2014-11-18 20:07 261人阅读 评论(0) 收藏
在Latex中插入图片的方式很多,我这里只介绍自己常用的一种方式,欢迎大家指导. 我习惯于使用graphicx宏包来插入图片,有时候会配合上subfigure宏包来同时插入多幅图片组合. 首先,需要在 ...
- app 的内存优化
这篇文章是笔者在开发App过程中发现的一些内存问题, 然后学习了YYKit框架时候也发现了图片的缓存处理 (YYKit 作者联系了我, 说明了YYKit重写imageNamed:的目的不是为了内存管理 ...
- ProGuard详解
综述 对于ProGuard工具想必我们都不陌生,它能够通过移除无用代码,使用简短无意义的名称来重命名类,字段和方法.从而能够达到压缩.优化和混淆代码的目的.最终我们会获取一个较小的apk文件,并且我们 ...
- ip、数字的互转
# ip ==> 数字 >>> ip2num = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[: ...
- Java使用poi对Execl简单操作_总结
poi是Apache组织给开发者提供一套操作office(Execl,Word,PowerPoint)等Java API,开发者通过Poi API可以快速的操作office办公软件,以上3篇博文只是一 ...
- (转)Linux内核之进程和系统调用
Linux内核之进程和系统调用 什么是系统调用 在Linux的世界里,我们经常会遇到系统调用这一术语,所谓系统调用,就是内核提供的.功能十分强大的一系列的函数.这些系统调用是在内核中实现的,再通过一定 ...
- Java中JIN机制及System.loadLibrary() 的执行过程
Android平台Native开发与JNI机制详解 http://mysuperbaby.iteye.com/blog/915425 个人认为下面这篇转载的文章写的很清晰很不错. 注意Android平 ...
- Linux软件
网上下载:Chrome Browser for Linux; sqlite; WPS; symbol-fonts; 软件中心:Terminator; Code::Blocks IDE; 新立得软件 ...