多校4 1001 Olympiad

Olympiad

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1118    Accepted Submission(s): 664

Problem Description

You are one of the competitors of the Olympiad in numbers. The problem of this year relates to beatiful numbers. One integer is called beautiful if and only if all of its digitals are different (i.e. 12345 is beautiful, 11 is not beautiful and 100 is not beautiful). Every time you are asked to count how many beautiful numbers there are in the interval [a,b] (a≤b). Please be fast to get the gold medal!

Input

The first line of the input is a single integer T (T≤1000), indicating the number of testcases.

For each test case, there are two numbers a and b, as described in the statement. It is guaranteed that 1≤a≤b≤100000.

Output

For each testcase, print one line indicating the answer.

Sample Input

2
1 10
1 1000

Sample Output

10
738

#include<cstdio>
int a[100005];
int num[10];
int main()
{
    int T, t, f, l, r;
    a[0] = 0;
    for(int i = 1; i <= 100000; i++){
        for(int j = 0; j < 10; j++){
            num[j] = 0;
        }
        f = 0;
        t = i;
        while(t != 0){
            if(num[t % 10] == 1){
                f = 1;
                break;
            }
            else{
                num[t % 10] = 1;
            }
            t = t / 10;
        }
        if(f == 0){
            a[i] = a[i-1] + 1;
        }
        else{
            a[i] = a[i-1];
        }
    }
    scanf("%d", &T);
    while(T--){
        scanf("%d%d", &l, &r);
        printf("%d\n", a[r] - a[l-1]);
    }
}

时间: 2024-10-31 17:14:52

多校4 1001 Olympiad的相关文章

HDU 4861(多校)1001 Couple doubi

Problem Description DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of this game is as following. There are k balls on the desk. Every ball has a value and the value of ith (i=1,2,...,k)

多校5 1001 HDU5781 ATM Mechine 记忆化搜索+概率

1 // 多校5 1001 HDU5781 ATM Mechine 2 // http://acm.hdu.edu.cn/search.php?field=problem&key=2016+Multi-University+Training+Contest+5&source=1&searchmode=source 3 // 记忆化搜索 4 // 每次二分,决策最优,所以最多查询11次 5 // dp[i][j] 当前能确定i元情况下,还能被警告j次 6 // 下次取k,实际剩余t

多校6 1001 HDU5793 A Boring Question (推公式 等比数列求和)

题解:http://bestcoder.hdu.edu.cn/blog/ 1 多校6 1001 HDU5793 A Boring Question 2 3 4 // #pragma comment(linker, "/STACK:102c000000,102c000000") 5 // #include <conio.h> 6 #include <bits/stdc++.h> 7 using namespace std; 8 #define clc(a,b) m

2015 多校赛 1001 (hdu 5288)

Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy a imod a j=0,now OO want to know [∑i=1n ∑j=i n f(i,j) ] mod (10^9+7) Input There are mult

OO’s Sequence 2015多校联合1001

题意:给一个n,然后n个数,求∑i=1n∑j=inf(i,j) mod (109+7). 也就是求n*(n+1)/2个区间内,给定一个i,使得i的左右两边的数都不能被a[i] eg. 5 1 2 3 4 5 一个有5*6/2=15个区间即15个f[l,r] [1,1] [1,2] [1,3] [1,4][1,5] [2,2] [2,3] [2,4][2,5] [3,3] [3,4][3,5] [4,4][4,5] [5,5] 设总数为sum 对于区间[1,1] 其中当i=1时,左右没有数被他整除

多校I 1001

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 888    Accepted Submission(s): 335 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the nu

hdu 5288||2015多校联合第一场1001题

http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i

2014多校第五场1001 || HDU 4911 Inversion (归并求逆序数)

题目链接 题意 : 给你一个数列,可以随意交换两相邻元素,交换次数不超过k次,让你找出i < j 且ai > aj的(i,j)的对数最小是多少对. 思路 : 一开始想的很多,各种都想了,后来终于想出来这根本就是求逆序数嘛,可以用归并排序,也可以用树状数组,不过我们用树状数组做错了,也不知道为什么.求出逆序数来再减掉k次,就可以求出最终结果来了.求逆序数链接1,链接2 1 #include <stdio.h> 2 3 int left[250003], right[250003];

2014多校8(1001)hdu4945(dp+组合数计数+求逆元)

2048 Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 566    Accepted Submission(s): 129 Problem Description Teacher Mai is addicted to game 2048. But finally he finds it's too hard to get 2048.