ural1057 Amount of degrees 位数统计
#include <iostream>
#include <string>
using namespace std; int f[][];
void init(){
f[][] =;
for(int i=;i<=;i++){
f[i][] = f[i-][];
for(int j=;j<=i;j++)
f[i][j] = f[i-][j]+f[i-][j-];
}
} int change(int x,int b){
string s;
while(x){
s = (char)(x%b+'')+s;
x = x/b;
}
for(int i=;i<s.size();i++)
if(s[i]>''){
for(int j=i;j<s.size();j++)
s[j] = '';
break;
}
x =;
for(int i=;i<s.size();i++){
x = x|((s[s.size()--i]-'')<<i);
}
return x;
} int cal(int x,int k){
int tot =,ans =;
for(int i=;i>;i--){
if(x&(<<i)){
tot++;
if(tot>k) break;
x = x^(<<i);
}
if((<<(i-))<=x){
ans += f[i-][k-tot];
}
}
if(tot + x==k) ans++;
return ans;
} int main()
{
init();
int x,y;
int k,b;
cin>>x>>y>>k>>b;
x= change(x,b);
y = change(y,b);
int resx = cal(x-,k);
int resy = cal(y,k);
cout<<resy-resx<<endl;
return ;
}
ural1057 Amount of degrees 位数统计的更多相关文章
- [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 ...
- [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 ...
- Ural1057. Amount of Degrees 题解 数位DP
题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...
- Ural1057 - Amount of Degrees(数位DP)
题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...
- ural1057 Amount of Degrees
链接 这题有一点小坑点 就是AX^B A只能为0或者1 ,剩下的就比较好做的了. #include <iostream> #include<cstdio> #include ...
- URAL1057. Amount of Degrees(DP)
1057 简单的数位DP 刚开始全以2进制来算的 后来发现要找最接近x,y值的那个基于b进制的0,1组合 #include <iostream> #include<cstdio&g ...
- 一本通1585【例 1】Amount of Degrees
1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...
- Ural Amount of Degrees(数位dp)
传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...
- [TimusOJ1057]Amount of Degrees
[TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...
随机推荐
- AS3事件机制概述
事件机制是AS3的核心功能之一,没有充分掌握事件机制的方方面面,就不能算是精通AS3语言. 1. AS3事件机制的主要成员 IEventDispatcher:事件派发对象接口,定义了添加.派发.移除. ...
- 枚举与剪枝_观察算式(比标准答案还要牛B)
观察算式 观察以下的算式: △△△ * △△ = △△△△ 某3位数乘以2位数,结果为4位数 要求:在9个△所代表的数字中.1~9的数字恰好每一个出现1次. 暴力破解代码: package lianx ...
- 从ACM中删除一个已经创建的Library
从ACM中删除一个已经创建的Library,无法通过界面操作,须要手工从DB中删除.须要删除的表记录有: RECENTUPDATE 找到字段Name等于该libraryName的那条记录删除掉 del ...
- Python入门-函数的使用到程序的公布安装
Python入门-函数的使用到Python的公布安装 本文主要适合有一定编程经验,至少掌握一门编程语言的人查看. 文中样例大多都是简单到认识英文单词就能看懂的水平,主要讲的是Python的总体使用方法 ...
- C#文件压缩
/// <summary> /// 文件压缩 /// </summary> /// <param name="filesUrl">多个文件路径& ...
- Hadoop 架构初探
对流行Hadoop做了一些最基本的了解,暂时没太大感觉,恩先记点笔记吧. = = Hadoop 基本命令及环境安装 一.下载虚拟机镜像 目前比较流行的有以下三个: (CHD) http://www.c ...
- Nio Client
public class NIOClient { static int SIZE = 2; final static int bufferSize = 500 * 1024; static InetS ...
- A - 数塔
A - 数塔 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- bzoj 1085: [SCOI2005]骑士精神 IDA*
题目链接 给一个图, 目标位置是确定的, 问你能否在15步之内达到目标位置. 因为只有15步, 所以直接ida* #include<bits/stdc++.h> using namespa ...
- 应该知道的Linux技巧
作者:陈皓(花名:钻风) 这篇文章来源于Quroa的一个问答<What are some time-saving tips that every Linux user should know?& ...