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 ;
}

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

  1. hdu 5327 Olympiad

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5327 Olympiad Description You are one of the competit ...

  2. HDU - 5327 Olympiad(一维前缀和)

    Olympiad Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem ...

  3. HDU 5327 Olympiad (水题)

    题意:beautiful数字定义为该数字中的十进制形式每一位都不同,给一个区间[L,R],求该区间中有多少个beautiful数字. 思路:数字不大,直接暴力预处理,再统计区间[1,i]有多少个,用c ...

  4. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  5. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  6. HDU 5792---2016暑假多校联合---World is Exploding

    2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...

  7. HDU 6143 17多校8 Killer Names(组合数学)

    题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...

  8. HDU 6045 17多校2 Is Derek lying?

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others)    Memory ...

  9. Time Zone 【模拟时区转换】(HDU暑假2018多校第一场)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6308 Time Zone Time Limit: 2000/1000 MS (Java/Others)  ...

随机推荐

  1. CentOS6配置静态IP

    CentOS6配置静态IP 1. 编辑网卡配置 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 HWADDR=不需要改 TYPE=Et ...

  2. 【LeetCode】Unique Email Addresses(独特的电子邮件地址)

    这道题是LeetCode里的第929道题. 题目要求: 每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而  ...

  3. Leetcode 334.递增的三元子序列

    递增的三元子序列 给定一个未排序的数组,判断这个数组中是否存在长度为 3 的递增子序列. 数学表达式如下: 如果存在这样的 i, j, k,  且满足 0 ≤ i < j < k ≤ n- ...

  4. php(ajax)异步刷新(转)

    第一种方法,ajax实现:当然,ajax使用起来确实很简单就可以实现,但是里面的很多知识还是比较有点深的.我之前做页面时间自动刷新的功能就是用的ajax.完整代码是:1.getTime.php: 复制 ...

  5. hdu2024

    这题目感觉不是很严谨,如果是关键字的话也是不能作为合法标识符的,但是这个不用检测,就算要检测也会很费劲,还得用字符串匹配,而且还得知道一共都有哪些关键字,太麻烦了,所以出题人原意就是检查大小写字母数字 ...

  6. Result实现类

    package org.apache.struts2.dispatcher; import com.opensymphony.xwork2.ActionInvocation; import com.o ...

  7. HDU——2112HDU Today(SPFA+简单Hash或map+前向星)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. VIJOS 1889 天真的因数分解 ——莫比乌斯函数

    同理BZOJ2440 二分答案,不过这次变成了统计含有平方因子的个数 #include <cmath> #include <cstdio> #include <cstri ...

  9. [BZOJ4506] [Usaco2016 Jan]Fort Moo(DP?)

    传送门 总之可以先预处理出来每个位置最多往上延伸多少 枚举两行,看看夹在这两行中间的列最大能构成多大的矩形 可以看出,必须得在一个两行都没有X的区间才有可能构成最大的答案 那么可以把这些区间处理出来, ...

  10. java面试题之能创建volatile数组吗?

    答:能,只不过只是一个指向数组的引用,而不是整个数组,如果改变了引用指向的数组,将会受到volatile的保护,但是如果多个线程同时改变数组的元素,volatile关键字就不能起到保护的作用.