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
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5352 5351 5350 5349 5348
 
开始想用字符串做,推出每一个数之前的美丽数的总和,再将a,b的总和数相减就是它们之间的美丽数之和了。但是做了半天还是没做出来,太麻烦。题解的做法是预处理,把每一个数是不是美丽数都判一遍,判的过程中用一个数组f记录这之前的美丽数之和,最后也是两个相减,也就是f[b]-f[a-1].
 #include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 123456
#define M 12 int a,b;
int ha[M],f[N];
int judge(int x)
{
int n;
memset(ha,,sizeof(ha));
while(x)
{
n=x%;
if(ha[n])return ;
else ha[n]=;
x=x/;
}
return ;
} int main()
{
f[]=;
for(int i=;i<;i++)
{
f[i]=f[i-];
if( judge(i) )
f[i]++;
}
int t;cin>>t;
while(t--)
{
scanf("%d%d",&a,&b);
cout<<f[b]-f[a-]<<endl;
}
return ;
}

最新文章

  1. ubuntu14.04安装及web环境的搭建
  2. LinQ C#防注入式攻击实例代码
  3. Struts2框架之-注解开发
  4. IE浏览器版本判断
  5. 重新延时运行的Js 实现
  6. DP(优化) UVALive 6073 Math Magic
  7. js中String.prototype.format類似于.net中的string.formitz效果
  8. eclipse中tomcat配置(待完善)
  9. snprintf 返回值
  10. AlertView with password
  11. win8 Pro 64位在 UEFI模式下Ghost系统 备份 恢复
  12. 实习小白笔记一(鼠标悬停、获取多选、提交修改、layer页面、单元格文字长度、json、分页、左连接)
  13. Tengine笔记3:Nginx的反向代理和健康状态检查
  14. LinqToXml高级用法介绍
  15. Dispose模式
  16. Java IO在实际开发中的应用
  17. Spring邮件发送1
  18. Objective-C的面向对象特性(二)
  19. Express框架之Jade模板引擎使用
  20. 表结构中updated_time设计为ON UPDATE CURRENT_TIMESTAMP时,使用过程的一个坑

热门文章

  1. AWK原理及命令和文件输入
  2. Python第三方库之openpyxl(5)
  3. [uiautomator篇] 基类
  4. acm之简单博弈 Nim Bash Wythoff
  5. Android从Fragment跳转到Activity
  6. bzoj2648/2716 kdtree
  7. asp.net mvc 页面内容呈现Html.Raw HtmlString
  8. python之基本数据类型及深浅拷贝
  9. Servlet 2.4 规范之第二篇:Servlet接口
  10. Oracle的memory_max_target和memory_target修改和ORA-00845: MEMORY_TARGET not supported on this system错误解决