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. PHP获取文件行数

    原文出处 提供两种实现方法,但是第一种效率最好 第一种: <?php $file_path = 'test.txt'; //文件路径 此处找一个1094644行的TXT文件 test.txt $ ...

  2. openURL的使用方法

    openURL的使用方法 openURL的使用方法: view plaincopy to clipboardprint? [[UIApplication sharedApplication] open ...

  3. An App ID with Identifier 'xxxxxx’ is not available. Please ....

    1.完全关闭Xcode; 2.找到钥匙串,将钥匙串(Keychain)中的对应证书移除: 3.再次打开Xcode,通过 Preferences - Account 4. 删除原先的账号重新登录, 搞定 ...

  4. 添加Appicon的方法

    1.将设计好的图片,拖拽到Groups&Files的Resources目录下: 2.修改Resources目录下的“工程名-info.plist”文件 3.修改该文件的Iconfile属性,填 ...

  5. (一)Nodejs - 框架类库 - Nodejs异步流程控制Async

    简介 Async是一个流程控制工具包,提供了直接而强大的异步功能 应用场景 业务流程逻辑复杂,适应异步编程,减少回调的嵌套 安装 npm insatll async 函数介绍 Collections ...

  6. 用response输出一个验证码

    package servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servle ...

  7. 第五篇、 WebSphere8.5的安装

    一.前言 WebSphere Application  Server 是IBM企业级应用服务器,与WAS6,WAS7相比较而言 WAS8发生了很大的改变,其安装介质和以前截然不同,该篇章中对于不同的安 ...

  8. xml 个人练习2

    package cn.gdpe.xml; import java.io.File;import java.io.FileInputStream;import java.io.IOException;i ...

  9. python3实现邮件发送程序

    刚开始的想法很简单,由于有上千封的邮件需要发出去,并且需要一条一条发送,不能转发或群发,每条邮件要署对方的姓名,并加上几个相同的符件,考虑到手工操作繁琐无趣,所以想到用程序实现,python好像非常胜 ...

  10. yii2源码学习笔记(四)

    继续了解组件Component.php /** * Returns a value indicating whether a property is defined for this componen ...