Classy Numbers
http://codeforces.com/group/w1oiqifZbS/contest/1036/problem/C
①先查找,存入vector(dfs)-->排序(sort)-->二分(lower_bound,upper_bound)
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<set>
#include<cctype>
#include<sstream>
#define mem(a) memset(a,0,sizeof(a))
#define LL long long
using namespace std;
const int N=1e6+;
vector<LL> ve;
LL n,l,r,m;
void dfs(LL now,int sum,int len)
{
ve.push_back(now);
if(len==)return;
dfs(now*,sum,len+); //十的倍数
if(sum<)
{
for(int i=;i<=;i++)
dfs(now*+i,sum+,len+);//其他,加一---非零
}
}
int main()
{
for(int i=;i<=;i++) //找到符合条件的数
dfs(i,,);
ve.push_back(1e18);//范围,不超过,且1e18符合
sort(ve.begin(),ve.end()); //lo,up要先排序
int t;
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d",&l,&r);
/*二分查找*/
int L=lower_bound(ve.begin(),ve.end(),l)-ve.begin();//返回第一个大于等于元素的下标
int R=upper_bound(ve.begin(),ve.end(),r)-ve.begin();//返回第一个大于的元素的下标;
printf("%d\n",R-L); //因为是up-lo,所以不用+1,且两个都是lo的话+1会在lr相等时出错
}
return ;
}
②查到发现还可以用数位DP mark一下
Classy Numbers的更多相关文章
- Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers
C. Classy Numbers 题目链接:https://codeforces.com/contest/1036/problem/C 题意: 给出n个询问,每个询问给出Li,Ri,问在这个闭区间中 ...
- CF1036C Classy Numbers dfs+二分
Classy Numbers time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces 1036C Classy Numbers 【DFS】
<题目链接> 题目大意: 对于那些各个位数上的非0数小于等于3的数,我们称为 classy number ,现在给你一个闭区间 [L,R] (1≤L≤R≤1018).,问你这个区间内有多 ...
- C. Classy Numbers
链接 [http://codeforces.com/contest/1036/problem/C] 题意 给你l,r,让你找在这个闭区间内位数不为0不超过3的个数,1<=l,r<=1e18 ...
- [CF1036C]Classy Numbers
题目大意:多个询问,每个询问问$[l,r](1\leqslant l\leqslant r\leqslant10^{18})$内有多少个数满足非零数位小于等于$3$. 题解:数位$DP$,$f_{i, ...
- 【Codeforces 1036C】Classy Numbers
[链接] 我是链接,点我呀:) [题意] 让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个. [题解] 只由3个非0数字组成的数字在1~10^18中只有60W个 dfs处理出来之 ...
- CF集萃1
因为cf上一堆水题,每个单独开一篇博客感觉不太好,就直接放一起好了. CF1096D Easy Problem 给定字符串,每个位置删除要代价.求最小代价使之不含子序列"hard" ...
- Educational Codeforces Round 50
1036A - Function Height 20180907 \(ans=\left \lceil \frac{k}{n} \right \rceil\) #include<bits/ ...
- nowcoder(牛客网)提高组模拟赛第一场 解题报告
T1 中位数(二分) 这个题是一个二分(听说是上周atcoder beginner contest的D题???) 我们可以开一个数组b存a,sort然后二分b进行check(从后往前直接遍历check ...
随机推荐
- 一文入门NodeJS
NodeJS¶ 1.环境配置¶ 之前讲ES6的时候有提过一部分Node的知识,简单回顾下:一文读懂ES6 1.1.NPM国内镜像¶ npm国内镜像:https://npm.taobao.org 配 ...
- CF226D The table
题目链接 题意 给出一个\(n\times m\)的矩阵,可以把某些行和某些列上面的数字变为相反数.问修改那些行和哪些列可以使得所有行和所有列之和都为非负数. 思路 每次将负数的行或者列变为相反数.因 ...
- html页面中引入自签名证书的js web资源出现net::ERR_CERT_AUTHORITY_INVALID
其实是浏览器客户端对自签名的内容认为不安全引起的,临时方法可以再浏览器中先直接访问下那个自签名的https地址,然后再访问有引用的那个页面就可以了. 以下内容引用自https://www.morong ...
- django系列 2 :启动应用,目录结构解读
来源:https://docs.djangoproject.com/en/2.1/intro/tutorial01/ 该教程是创建一个用于投票的网页. 1.使用命令创建site 进入要创建site的目 ...
- POJ 3186 Treats for the Cows (动态规划)
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...
- django - 总结 - ModelForm
gender = forms.ChoiceField(choices=((1, '男'), (2, '女'), (3, '其他'))) # 与sql没关系 publish = forms.Choice ...
- [再寄小读者之数学篇](2014-06-27 向量公式: The Hall term)
$$\bex \n\cdot{\bf b}=0\ra \n\times [(\n\times {\bf b})\times {\bf b}]=\n\times [\n\cdot ({\bf b}\ot ...
- react-router v4 按需加载的配置方法
在react项目开发中,当访问默认页面时会一次性请求所有的js资源,这会大大影响页面的加载速度和用户体验.所以添加按需加载功能是必要的,以下是配置按需加载的方法: 安装bundle-loader np ...
- cpp智能指针
weak_ptr<Cls1> wp1; { shared_ptr<Cls1> ptr1(new Cls1);//共享指针 wp1 = ptr1;//临时共享指针 std::co ...
- LOJ #556. 「Antileaf's Round」咱们去烧菜吧
好久没更博了 咕咕咕 现在多项式板子的常数巨大...周末好好卡波常吧.... LOJ #556 题意 给定$ m$种物品的出现次数$ B_i$以及大小$ A_i$ 求装满大小为$[1..n]$的背包的 ...