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 ...
随机推荐
- 【LR9】【LOJ561】CommonAnts 的调和数 数论 筛法
题目大意 有一个长度为 \(n\) 的序列. 有 \(m\) 次修改,每次给你 \(x,y\),令 \(\forall 1\leq i\leq \lfloor\frac{n}{x}\rfloor,a_ ...
- hdu 3480 Division(四边形不等式优化)
Problem Description Little D is really interested in the theorem of sets recently. There’s a problem ...
- vue实战记录(三)- vue实现购物车功能之渲染商品列表
vue实战,一步步实现vue购物车功能的过程记录,课程与素材来自慕课网,自己搭建了express本地服务器来请求数据 作者:狐狸家的鱼 本文链接:vue实战-实现购物车功能(三) GitHub:sue ...
- Redis知识整理
Redis知识整理 转自:https://www.cnblogs.com/rjzheng/p/9096228.html 1.单线程模型 Redis客户端对服务端的每次调用都经历了发送命令,执行命令,返 ...
- Geometric regularity criterion for NSE: the cross product of velocity and vorticity 1: $u\times \om$
在 [Chae, Dongho. On the regularity conditions of suitable weak solutions of the 3D Navier-Stokes equ ...
- Numpy 学习(一)
1.Numpy 中Matrices和arrays的区分 Numpy matrices必须是2维的,但是 numpy arrays (ndarrays) 可以是多维的(1D,2D,3D····ND). ...
- 利用div绘制细线居中
利用div配合css代码实现细线方式: 块级元素水平居中步骤: 设置宽度width 设置margin-left:auto; 设置margin-right:auto; 实现方法是,让其左右两边的外边距自 ...
- luogu P5300 [GXOI/GZOI2019]与或和
传送门 题目涉及按位与以及按位或运算,所以可以拆位考虑,枚举某个二进制位,然后某个位置如果那个数的第\(i\)位是\(0\)就放\(0\),否则放\(1\),这一位的贡献就是位运算后值为\(1\)的子 ...
- IDEA 中使用MyBatis-generator 自动生成MyBatis代码
0.在Intellij IDEA创建maven项目 1. 在maven项目的pom.xml 添加mybatis-generator-maven-plugin 插件 <build> < ...
- OGG微服务架构入门
数据复制任务路线图 设置数据复制必须执行许多任务. 下表列出了构建分发路径的阶段. Task Description 运行Oracle GoldenGate Configuration Assista ...