解题报告 之 HDU5327 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 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 









.
Please be fast to get the gold medal!











Input
The first line of the input is a single integer 








,
indicating the number of testcases.
For each test case, there are two numbers
and
,
as described in the statement. It is guaranteed that 










.










For each test case, there are two numbers














Output
For each testcase, print one line indicating the answer.
Sample Input
2 1 10 1 1000
Sample Output
10 738
题目大意:一个数被称为美丽数,如果它的每一位数都不一样。给出范围[L,R],为这个范围内有多少美丽数。
分析:就是直接朴素的做法看看每个数是不是美丽数,打表保存1~100000分别有几个美丽数,直接输出sum[R]-sum[L-1]即可。
上代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
const int MAXN = 1e5 + 10;
int num[MAXN];
void get()
{
num[0] = 0;
for(int i = 1; i < MAXN; i++)
{
num[i] = num[i - 1];
set<int> s;
int tem = i;
while(tem)
{
if(s.find( tem % 10 ) != s.end())
break;
s.insert( tem % 10 );
tem /= 10;
}
if(tem == 0)
num[i]++;
}
}
int main()
{
int n;
cin >> n;
get();
while(n--)
{
int a, b;
cin >> a >> b;
cout << num[b] - num[a - 1] << endl;
}
}