[TimusOJ1057]Amount of Degrees
[TimusOJ1057]Amount of Degrees
试题描述
18 = 24+21,
20 = 24+22.
输入
The first line of input contains integers X and Y, separated with a space (1 ≤ X ≤ Y ≤ 231−1). The next two lines contain integers K and B (1 ≤ K ≤ 20; 2 ≤ B ≤ 10).
输出
Output should contain a single integer — the amount of integers, lying between X and Y, being a sum of exactly K different integer degrees of B.
输入示例
输出示例
数据规模及约定
见“输入”
题解
就是看转换成 b 进制之后是不是只有 0 和 1 并且 1 的个数恰好等于 k。
行了,明白了题意,就没啥可说的了。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 35
#define maxk 25
int f[maxn][2][maxk], K, b; int num[maxn];
int sum(int x) {
int cnt = 0, tx = x;
while(x) num[++cnt] = x % b, x /= b;
int ans = 0, Cnt = 0;
for(int i = cnt; i; i--) {
for(int j = 0; j < min(2, num[i]); j++) ans += f[i][j][K-Cnt];
if(num[i] > 1){ Cnt = -1; break; }
Cnt += num[i];
}
ans += (Cnt == K);
return ans;
} int main() {
f[1][0][0] = 1; f[1][1][1] = 1;
for(int i = 1; i <= 32; i++)
for(int j = 0; j <= 1; j++)
for(int k = 0; k <= i; k++)
for(int x = 0; x <= 1; x++)
f[i+1][x][k+x] += f[i][j][k]; int l = read(), r = read(); K = read(); b = read();
printf("%d\n", sum(r) - sum(l - 1)); return 0;
}
[TimusOJ1057]Amount of Degrees的更多相关文章
- 一本通1585【例 1】Amount of Degrees
1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...
- 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 ...
- [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 ...
- Ural Amount of Degrees(数位dp)
传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...
- 【算法•日更•第十二期】信息奥赛一本通1585:【例 1】Amount of Degrees题解
废话不多说,直接上题: 1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB提交数: 130 通过数: 68 [ ...
- [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 ...
- 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 ...
- Ural1057. Amount of Degrees 题解 数位DP
题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...
- Ural 1057 Amount of Degrees
Description 问[L,R]中有多少能表示k个b次幂之和. Sol 数位DP. 当2进制时. 建出一个二叉树, \(f[i][j]\) 表示长度为 \(i\) 有 \(j\) 个1的个数. 递 ...
随机推荐
- 一个C#解决方案中各文件夹存放了些什么
在VS2015中"生成"(Build)的过程: Source Code(.cs) -> Compile -> Object File(intermediate file ...
- Canvas绘画功能(待补充)
由于项目的前端需要用户手绘输入,所以我们利用Canvas控件做绘画面板,并且实现了许多功能,包括手绘笔画,清空画板,上传手绘图,下载手绘图,记录用户笔画,上传背景图.以后有时间都写到这篇博客中,今天晚 ...
- c#优化
优化反射 http://kb.cnblogs.com/page/172119/ http://www.2cto.com/kf/201301/182765.html http://blog.sina.c ...
- 获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址(服务器端)
<?php class GetMacAddr{ var $return_array = array(); // 返回带有MAC地址的字串数组 var $mac_addr; function Ge ...
- mysql锁
锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许多用户共享的资源.如何保证数据并发访问的一致性.有效性是所有数 ...
- 字符串哈希函数(String Hash Functions)
哈希函数举例 http://www.cse.yorku.ca/~oz/hash.html Node.js使用的哈希函数 https://www.npmjs.org/package/string-has ...
- js无间隙滚动
代码一: ; //设置文字滚动速度 dome2.innerHTML=dome1.innerHTML //复制dome1为dome2 function Marquee(){ ) //当滚动至dome1与 ...
- PHP代码质量优化
最近总结了一些平常写PHP代码时的一些优化分享给大家. 1.尽量使用绝对路径 相对路径中会检查很多路径,这时我们可以使用绝对路径,但绝对路径不利于后期维护,所以define定义的时候使用__FILE_ ...
- nginx配置图片防盗链
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${ expires 30d; access_log off; valid_referers none blocked ...
- linq按条件sum
var result = fruit.GroupBy(i => i.date) .Select(i => new { date = i.Key, no_of_apple = i.Where ...