DFS。

 /* 5179 */
#include <iostream>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
using namespace std; #define MAXN 1500 map<int, bool> tb;
int a[MAXN], n, v;
int buf[][] = {
{,},
{,,,}, {,,,,},
{,,,}, {,,,},
{,,},
{,,}
}; void dfs(int beg, int len, int val) {
int i, k, tmp = *val;
if (len >= )
return ;
for (i=beg; i<=buf[v][]; ++i) {
k = tmp + buf[v][i];
if (!tb[k]) {
tb[k] = true;
a[n++] = k;
}
dfs(i, len+, k);
}
} void init() {
int i, j, k; n = ;
for (v=; v<; ++v)
dfs(, , );
sort(a, a+n);
} int main() {
int t, l, r;
int i, j, k;
int ans; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif init();
scanf("%d", &t);
while (t--) {
scanf("%d %d", &l, &r);
ans = ;
for (i=; i<n; ++i)
if (l<=a[i] && r>=a[i])
++ans;
printf("%d\n", ans);
} return ;
}

【HDOJ】5179 beautiful number的更多相关文章

  1. 【HDOJ】3948 The Number of Palindromes

    后缀数组求不重复回文子串数目.注意dp数组. /* 3948 */ #include <iostream> #include <sstream> #include <st ...

  2. 【HDOJ】4162 Shape Number

    循环串的最小表示法. /* */ #include <iostream> #include <string> #include <map> #include < ...

  3. 【HDOJ】1018 Big Number

    数学题,还是使用log避免大数,但是不要忘记需要+1,因为0也是1位,log(100)= 2,但却是3位. #include <stdio.h> #include <math.h&g ...

  4. 【HDOJ】3006 The Number of set

    数据量这么小,果断状态压缩+dp. /* 3006 */ #include <iostream> #include <string> #include <map> ...

  5. 【转】oracle数据库NUMBER数据类型

    原文:http://www.jb51.net/article/37633.htm NUMBER ( precision, scale)a)  precision表示数字中的有效位;如果没有指定prec ...

  6. 【CF245H】Queries for Number of Palindromes(回文树)

    [CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是 ...

  7. 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树

    [BZOJ4026]dC Loves Number Theory Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源.    给 ...

  8. 【题解】P4755 Beautiful Pair(启发式合并的思路+分治=启发式分治)

    [题解]P4755 Beautiful Pair upd: 之前一个first second烦了,现在AC了 由于之前是直接抄std写的,所以没有什么心得体会,今天自己写写发现 不知道为啥\(90\) ...

  9. 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)

    [LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

随机推荐

  1. 轻量级的原型设计工具-Axure RP

    1. 软件下载地址: http://www.downxia.com/downinfo/25742.html 这个版本不需要注册码,不需要安装,存绿色版. 2. 基本介绍教程: http://wenku ...

  2. Java基础知识强化之集合框架笔记33:Arrays工具类中asList()方法的使用

    1. Arrays工具类中asList()方法的使用 public static <T> List<T> asList(T... a): 把数组转成集合 注意事项: 虽然可以把 ...

  3. ubuntu下git clone 出现Permission denied (publickey).

    今天在ubuntu上使用git 克隆 github上面的库,一直权限拒绝Permission denied (publickey). 公钥绑了好几次,都不行: 最后怀疑是git配置公钥地址有问题:打开 ...

  4. jquery几个常用的demo

    新建两个页面.一个叫做  ---- demo1.js------- 一个叫做 ----- demo1.html----- 代码分别如下 <!DOCTYPE html> <html l ...

  5. C#语法糖之开篇

    本人虽然大学不是学的计算机但是对于IT行业的热爱,依然决然进军IT行业了,自从踏进这个行业到现在也已经3年多了,从去年开发通过网上 了解博客园后深深的爱上这儿了,这里有很多牛人,通过拜读他们的代码,让 ...

  6. linux的grep命令

    参考文档如下: linux grep命令 grep abb15455baeb4b23ab47540272ec47eb epps-sas.log | grep operateSettleBill exp ...

  7. Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

    canvas绘制图片,由于浏览器的安全考虑,如果在使用canvas绘图的过程中,使用到了外域的图片资源,那么在toDataURL()时会抛出安全异常: Uncaught SecurityError: ...

  8. Encapsulation.

    Access control is often referred to as implementation hiding. Wrapping data and methods within class ...

  9. 在使用Kettle的集群排序中 Carte的设定——(基于Windows)

    本片文章主要是关于使用Kettle的UI界面: Spoon来实现基于集群的对数据库中的数据表数据进行排序的试验. 以及在实验过程中所要开启的Carte服务的一些配置文件的设置, 还有基于Windows ...

  10. 菜鸟学开店—自带U盘的打印机

    本文旨在提供最简单.便宜.有效的解决方案,解决普通用户最困扰的问题.今天提供普通用户一个低价的小票打印机驱动安装解决方案 相信很多用户都碰到过这种情况,电脑的重装了系统,打印机的驱动没有备份,要用打印 ...