HDU5327(基础题)
2016-07-12 09:32
288 查看
题目:
G - Olympiad
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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)[a,b]\ (a \le b). Please be fast to get the gold medal!
Input
The first line of the input is a single integer T (T≤1000)T\ (T \le 1000), indicating the number of testcases.
For each test case, there are two numbers aa and bb, as described in the statement. It is guaranteed that 1≤a≤b≤1000001 \le a \le b \le 100000.
Output
For each testcase, print one line indicating the answer.
Sample Input
2
1 10
1 1000
Sample Output
10
738
题意:
找出所给范围的漂亮数(每个数位上的数互不相同)
思路:
数据范围会很大,暴力的话会重复多次求解,那么打表,表中每个arr[i]记录前i个数中有多少个漂亮数,并且判断i是不是漂亮数,一直累加,求解时区间相减,注意还有判断区间起始值a是否为漂亮数,并且加上。
代码:
check()函数判断是否为漂亮数,printList()函数打表,其中check()函数返回值设为int,返回值为1或0,可以在最后区间相减的时候判断区间开始的数是否为漂亮数。
G - Olympiad
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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)[a,b]\ (a \le b). Please be fast to get the gold medal!
Input
The first line of the input is a single integer T (T≤1000)T\ (T \le 1000), indicating the number of testcases.
For each test case, there are two numbers aa and bb, as described in the statement. It is guaranteed that 1≤a≤b≤1000001 \le a \le b \le 100000.
Output
For each testcase, print one line indicating the answer.
Sample Input
2
1 10
1 1000
Sample Output
10
738
题意:
找出所给范围的漂亮数(每个数位上的数互不相同)
思路:
数据范围会很大,暴力的话会重复多次求解,那么打表,表中每个arr[i]记录前i个数中有多少个漂亮数,并且判断i是不是漂亮数,一直累加,求解时区间相减,注意还有判断区间起始值a是否为漂亮数,并且加上。
代码:
#include <iostream> #include <cstring> const int maxn = 100000+10; int arr[maxn]; int node[10]; using namespace std; int check(int a){ memset(node, 0, sizeof(node)); while(a){ node[a%10]++; if(node[a%10]>1) return 0; a = a/10; } return 1; } void printList(){ memset(arr, 0, sizeof(arr)); for(int i=0; i<=100010; i++){ if(check(i)){ //cout<<"i is:"<<i<<endl; arr[i] = arr[i-1] + 1;} else arr[i] = arr[i-1]; } } int main(){ int n, a, b; while(cin>>n){ printList(); for(int i=0; i<n; i++){ cin>>a>>b; cout<<arr[b]-arr[a]+check(a)<<endl; } } return 0; }
check()函数判断是否为漂亮数,printList()函数打表,其中check()函数返回值设为int,返回值为1或0,可以在最后区间相减的时候判断区间开始的数是否为漂亮数。
相关文章推荐
- 格式化一个文件的大小(size),或者说是格式化一个app的大小(size)
- 虚拟化天花板将近,后虚拟化时代如何应对?
- ARM学习步骤
- Android Studio系列教程二--基本设置与运行
- JDBC快速入门教程
- dubobo接口的泛化调用(不依赖jar包)
- 接口定义步骤
- Managing Bitmap Memory
- 进程的基本状态
- 写给新人的面向对象的基本思维
- 【技术晨读】程序员的基础生存技能:高效用Google
- 【打CF,学算法——四星级】CodeForces 31E TV Game (动态规划)
- iOS 偏好设置-简单使用
- spring
- 解析网络数据之前先?
- 读《世界梦幻图书馆》(日)
- 一.4文件操作---4.1二进制
- figure和mark元素
- PLC学习笔记1 接触器的使用和接线
- Android动画:帧动画、补间动画、属性动画