解题报告 之 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
![](https://i-blog.csdnimg.cn/blog_migrate/a1809c6a37efb3216c8343a8d0221e27.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6819ad02b70c45921b71f613da72f0f8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/cb10f59dbf3015a94b8c009b13856360.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25da3021e94f663f575c49ea7a9a9fc1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6819ad02b70c45921b71f613da72f0f8.png)
. Please be fast to get the gold medal!
![](https://i-blog.csdnimg.cn/blog_migrate/a1809c6a37efb3216c8343a8d0221e27.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0078e2c51675107576ccab364cd305ec.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6819ad02b70c45921b71f613da72f0f8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/cb10f59dbf3015a94b8c009b13856360.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25da3021e94f663f575c49ea7a9a9fc1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6819ad02b70c45921b71f613da72f0f8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9f61591de1c8a8c5f8c7d228814838c5.png)
Input
The first line of the input is a single integer
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25da3021e94f663f575c49ea7a9a9fc1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
, indicating the number of testcases.
For each test case, there are two numbers
and
, as described in the statement. It is guaranteed that
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6819ad02b70c45921b71f613da72f0f8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
.
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25da3021e94f663f575c49ea7a9a9fc1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9f61591de1c8a8c5f8c7d228814838c5.png)
For each test case, there are two numbers
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6819ad02b70c45921b71f613da72f0f8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0815e7e68da82e60bdb79395822f6d97.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6819ad02b70c45921b71f613da72f0f8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
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;
}
}