【链接】 我是链接,点我呀:)

【题意】

让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个.

【题解】

只由3个非0数字组成的数字在1~10^18中只有60W个
dfs处理出来之后排序做个二分查找一下区间里有多少个就好。

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = 700000;
static class Task{
TreeSet<Long> myset = new TreeSet<Long>();
long a[] = new long[N+10];
int T,n;
long l,r; void dfs(long cur,int num,int dep) {
if (dep==18) {
if (cur>0) myset.add(cur);
return;
}
if (num<3) {
for (int j = 1;j <= 9;j++)
dfs(cur*10+j,num+1,dep+1);
}
dfs(cur*10,num,dep+1);
} int get_least_gore(long x) {
int l = 1,r = n,temp = 1;
while (l<=r) {
int mid = (l+r)/2;
if (a[mid]>=x) {
temp = mid;
r = mid - 1;
}else l = mid + 1;
}
return temp;
} int get_last_lore(long x) {
int l = 1,r = n,temp = 1;
while (l<=r) {
int mid = (l+r)/2;
if (a[mid]<=x) {
temp = mid;
l = mid + 1;
}else r = mid - 1;
}
return temp;
} public void solve(InputReader in,PrintWriter out) {
myset.add((long)1e18);
dfs(0,0,0);
n = myset.size();
Iterator<Long> it = myset.iterator();
int j = 1;
while (it.hasNext()) {
a[j] = it.next();
j++;
}
T = in.nextInt();
for (int ii = 1;ii <= T;ii++) {
l = in.nextLong();r = in.nextLong();
int idx1 = get_least_gore(l);
int idx2 = get_last_lore(r);
out.println(idx2-idx1+1);
}
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
}
}
}

【Codeforces 1036C】Classy Numbers的更多相关文章

  1. 【Codeforces 300C】Beautiful Numbers

    [链接] 我是链接,点我呀:) [题意] 让你找到长度为n的数字 这个数字只由a或者b组成 且这n个数码的和也是由a或者b组成的 求出满足这样要求的数字的个数 [题解] 枚举答案数字中b的个数为y,那 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【66.47%】【codeforces 556B】Case of Fake Numbers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 746E】Numbers Exchange

    [题目链接]:http://codeforces.com/problemset/problem/746/E [题意] 你有n张卡片,上面写着不同的数字; 然后另外一个人有m张上面写着不同的数字的卡片: ...

  5. 【codeforces 367C】Sereja and the Arrangement of Numbers

    [题目链接]:http://codeforces.com/problemset/problem/367/C [题意] 我们称一个数列a[N]美丽; 当且仅当,数列中出现的每一对数字都有相邻的. 给你n ...

  6. 【19.77%】【codeforces 570D】Tree Requests

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【35.37%】【codeforces 556C】Case of Matryoshkas

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. jquery对所有<input type="text"的控件赋值

    function resetData() {      $("input[type=text]").each(      function() {     $(this).attr ...

  2. bzoj3450 Easy(概率期望dp)

    3450: Tyvj1952 Easy Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 876  Solved: 648[Submit][Status] ...

  3. golang——随机数(math/rand包与crypto/rand包)

    1.math/rand 包 1.1.math/rand 包实现了伪随机数生成器 1.2.主要方法 (1)func Seed(seed int64) 设置随机种子,不设置则默认Seed(1) (2)fu ...

  4. (分治)51NOD 1019 逆序数

    在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.   如2 4 3 1中,2 1,4 3,4 1,3 1是 ...

  5. jSignature做手动签名,canvas支持触摸屏的签名涂鸦插件

    整理的前面可以用的: <!doctype html> <html lang="en"> <head> <meta charset=&quo ...

  6. vue中sync,v-model----双向数据绑定

    需求:父子组件同步数据 实现方式:sync或者v-model 一.sync 官网:https://cn.vuejs.org/v2/guide/components-custom-events.html ...

  7. 洛谷2019 3月月赛 T4

    T3做不来.. 直接滚去T4 orz 乍一看 T4是个DP 题干 复杂度??(N^4) 咋优化... 还带一只捆绑 捆绑啥的最烦人了 最后20pts 直接废了 T了 很烦 不过拿到80pts已经很开心 ...

  8. 生成 Guid

    //生成Guid    function getGuidGenerator() {        var S4 = function () {            return (((1 + Mat ...

  9. 368 Largest Divisible Subset 最大整除子集

    给出一个由无重复的正整数组成的集合, 找出其中最大的整除子集, 子集中任意一对 (Si, Sj) 都要满足: Si % Sj = 0 或 Sj % Si = 0.如果有多个目标子集,返回其中任何一个均 ...

  10. 漫谈未来的HDFS

    前面我们提到的HDFS,了解了HDFS的特性和架构.HDFS能够存储TB甚至PB规模的数据是有前提的,首先数据要以大文件为主,其次NameNode的内存要足够大.对HDFS有所了解的同学肯定都知道,N ...