HDU 5327 Olympiad (多校)

Olympiad

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

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

Author

XJZX

Source

2015 Multi-University Training Contest 4

Recommend

wange2014   |   We have carefully selected several similar problems for you:  5352 5351 5350 5349 5348

开始想用字符串做,推出每一个数之前的美丽数的总和,再将a,b的总和数相减就是它们之间的美丽数之和了。但是做了半天还是没做出来,太麻烦。题解的做法是预处理,把每一个数是不是美丽数都判一遍,判的过程中用一个数组f记录这之前的美丽数之和,最后也是两个相减,也就是f[b]-f[a-1].

 1 #include<queue>
 2 #include<math.h>
 3 #include<stdio.h>
 4 #include<string.h>
 5 #include<iostream>
 6 #include<algorithm>
 7 using namespace std;
 8 #define N 123456
 9 #define M 12
10
11 int a,b;
12 int ha[M],f[N];
13 int judge(int x)
14 {
15     int n;
16     memset(ha,0,sizeof(ha));
17     while(x)
18     {
19         n=x%10;
20         if(ha[n])return 0;
21         else ha[n]=1;
22         x=x/10;
23     }
24     return 1;
25 }
26
27 int main()
28 {
29     f[0]=1;
30     for(int i=1;i<100005;i++)
31     {
32         f[i]=f[i-1];
33         if( judge(i) )
34             f[i]++;
35     }
36     int t;cin>>t;
37     while(t--)
38     {
39         scanf("%d%d",&a,&b);
40         cout<<f[b]-f[a-1]<<endl;
41     }
42     return 0;
43 }
时间: 2024-10-10 22:35:57

HDU 5327 Olympiad (多校)的相关文章

hdu 5327 Olympiad (多校联赛) ——模拟

here 题意:给你两个数,让你求出这两个数之间有多少个数,这个数满足他的每一位的数都不相同.例如 113 不满足 143 满足. 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

HDU 5327(2015多校4)-Olympiad(水题)

题目地址:HDU 5327 题意:beautiful numbers的定义:就是一个数的每一位不能有相同的数字,现在给你一个区间,让你求这区间内有多少个这样的漂亮数. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algori

hdu 5327 Olympiad

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5327 Olympiad 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 digita

HDU 5327 Olympiad (水题)

题意:beautiful数字定义为该数字中的十进制形式每一位都不同,给一个区间[L,R],求该区间中有多少个beautiful数字. 思路:数字不大,直接暴力预处理,再统计区间[1,i]有多少个,用cnt[R]-cnt[L-1]即可. 1 #include <bits/stdc++.h> 2 #define INF 0x7f7f7f7f 3 #define pii pair<int,int> 4 #define LL long long 5 using namespace std;

HDU 4864(多校)1004 Task

Problem Description Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task's level yi cannot complete this task. If the company comp

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)

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

HDU 4862 Jump (2014-多校1-1002,最小K路径覆盖,最小费用最大流)

题目: http://acm.hdu.edu.cn/showproblem.php?pid=4862 题意: 给你一个n*m的矩阵,填充着0-9的数字,每次能从一个点出发,到它的右边或者下边的点,花费为|x1-x2|+|y1-y2|-1,如果跳跃的起点和终点的数字相同,则获得这个数字的收益,不能走已经走过的点 有K次重新选择起点的机会 如果可以走遍所有点,则输出最大的价值(收益-花费) 否则,输出-1 方法: 最小K路径覆盖,最小费用最大流 建图: 每个点拆为2点:X部和Y部,(a,b)表示流量

HDU 5347(2015多校5)-MZL&#39;s chemistry(打表)

题目地址HDU 5347 无脑流神题,自行脑补,百度大法好. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #