【HDOJ】5179 beautiful number
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的更多相关文章
- 【HDOJ】3948 The Number of Palindromes
后缀数组求不重复回文子串数目.注意dp数组. /* 3948 */ #include <iostream> #include <sstream> #include <st ...
- 【HDOJ】4162 Shape Number
循环串的最小表示法. /* */ #include <iostream> #include <string> #include <map> #include < ...
- 【HDOJ】1018 Big Number
数学题,还是使用log避免大数,但是不要忘记需要+1,因为0也是1位,log(100)= 2,但却是3位. #include <stdio.h> #include <math.h&g ...
- 【HDOJ】3006 The Number of set
数据量这么小,果断状态压缩+dp. /* 3006 */ #include <iostream> #include <string> #include <map> ...
- 【转】oracle数据库NUMBER数据类型
原文:http://www.jb51.net/article/37633.htm NUMBER ( precision, scale)a) precision表示数字中的有效位;如果没有指定prec ...
- 【CF245H】Queries for Number of Palindromes(回文树)
[CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是 ...
- 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树
[BZOJ4026]dC Loves Number Theory Description dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给 ...
- 【题解】P4755 Beautiful Pair(启发式合并的思路+分治=启发式分治)
[题解]P4755 Beautiful Pair upd: 之前一个first second烦了,现在AC了 由于之前是直接抄std写的,所以没有什么心得体会,今天自己写写发现 不知道为啥\(90\) ...
- 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)
[LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
随机推荐
- Android(java)学习笔记197:常用的对话框
一.常见对话框属性: 1. AlertDialog.Builder属性 • setTitle: 为对话框设置标题 :• setIcon : 为对话框设置图标:• setMessage: 为对话框设置 ...
- frame模型
#import "CZWeiboFrame.h" #import "CZWeibo.h" @implementation CZWeiboFrame #defin ...
- AS【常用插件】
安装插件,Settings -->[Plugins]-->搜索-->点击install-->重启AS 禁用插件,右侧面板会显示出已经安装的插件列表,取消勾选即可禁用插件 AS插 ...
- HTML5小游戏源码收藏
html5魅族创意的贪食蛇游戏源码下载 html5网页版打砖块小游戏源码下载 html5 3D立体魔方小游戏源码下载 html5网页版飞机躲避游戏源码下载 html5三国人物连连看游戏源码下载 js ...
- DataTable和List集合互转
/// <summary> /// 将集合转换成DataTable /// </summary> /// <param name="list"> ...
- 直接修改workspace下的配置文件与tomcat下的文件
项目中直接修改workspace下的配置文件与tomcat下的文件,可是还有错误,例如修改了4个配置文件中的一个配置文件.经查如下: 直接修改workspace下的配置文件与tomcat下的文件,可能 ...
- Eclipse中看java源代码
如何在Eclipse sdk中查看jar源代码如:*.jar 1.点 “window”-> "Preferences" -> "Java" -> ...
- redhat6.4 配置centos6 yum替换
1.卸载掉系统redhat自带的yum rpm -qa |grep yum |xargs rpm -e --nodeps 2 下载相关的centos yum插件 主要有python-inipa ...
- OC - 19.GCD
简介 GCD(Grand Center Dispatch)是Apple为多核的并行运算提出的解决方案,纯C语言 更加适配多核处理器,且自动管理线程的生命周期,使用起来较为方便 GCD通过任务和队列实现 ...
- html 5的localstorag
随着我们硬件技术的发展,浏览器本身的功能也愈发的完善,从之前的cookie到现在的本地缓存机制,再到web storage,在之前html4 的时候使用cookie具有一些明显的局限,如大小限制,co ...