题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5327

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 $[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 \leq 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 \leq a \leq b \leq 100000$.

Output

For each testcase, print one line indicating the answer.

Sample Input

2
1 10
1 1000

Sample Output

10
738

暴力枚举,前缀和。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using std::map;
using std::min;
using std::find;
using std::pair;
using std::vector;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 100001;
const int INF = 0x3f3f3f3f;
int vis[10], sum[N + 10];
void init() {int v, j;sum[0] = 0;for(int i = 1; i <= N; i++) {v = i;bool f = true;cls(vis, 0);do vis[v % 10]++; while(v /= 10);for(j = 0; j < 10; j++) {if(vis[j] > 1) { f = false; break;}}sum[i] = sum[i - 1] + f;}
}
int main() {
#ifdef LOCALfreopen("in.txt", "r", stdin);freopen("out.txt", "w+", stdout);
#endifinit();int t, x, y;scanf("%d", &t);while(t--) {scanf("%d %d", &x, &y);printf("%d\n", sum[y] - sum[x - 1]);}return 0;
}

转载于:https://www.cnblogs.com/GadyPu/p/4796277.html

hdu 5327 Olympiad相关推荐

  1. [HDOJ5327]Olympiad

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5327 打表预处理数据范围内所有的符合条件的数再查询即可. 1 #include <cstdio& ...

  2. hdu 3631 Shortest Path(Floyd)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3631 Shortest Path Time Limit: 3000/1000 MS (Java/Oth ...

  3. HDU 4389 - X mod f(x)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4389 2012多校,第9场,1010 . 问题是,询问区间内 存在多少个 哈沙德数(Harshad ...

  4. HDU-5327 Olympiad (前缀和水题)

    题目链接:Problem - 5327 (hdu.edu.cn) 题目: 题目样例: 题目思路: 每次的范围去暴力会超时,采取用前缀和来进行预处理,再进行查询. AC: #include<bit ...

  5. hdu 4389 囧,打表

    http://acm.hdu.edu.cn/showproblem.php?pid=4389 题意 :一个数能被他各个位数之和整除则符合要求,给L,R,问区间里有多少个数符合要求. 囧,居然打表就能过 ...

  6. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  7. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

  8. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

  9. hdu 1312 Red and Black 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 第二条深搜,题目并不难,但是做了我好久好久,由于一个细节,让我赌上了一个晚上的时间. 题目大意: ...

最新文章

  1. java中let_java Signleton模式详解及示例代码
  2. 冒泡排序算法_PHP冒泡排序算法(一)
  3. Ubuntu安装MySQL1 - 失败
  4. HDU 1828 Picture 线段树 扫描线
  5. Java—遍历集合的N种方式总结Collections工具类
  6. 关于支付宝即时到帐异步通知(notify_url)一点总结
  7. mysql有没有类似merge_有关于Mysql的MERGE表类型
  8. 前后端配合实现密码找回功能思路
  9. python内建函数(不完全)
  10. Androidstudio设置Ctrl+W关闭当前编辑的页面窗口
  11. Adobe放出P图新研究:就算丢了半个头,也能逼真复原
  12. Word 2007翻译里一个诡异的问题——微软的疏忽还是一个Joke?
  13. 小学计算机课教后小记,小学信息技术课开展生活化教学的方法
  14. Win32汇编——钩子
  15. show,hide与fadeIn、fadeOu的区别
  16. 给新服务器装linux系统,新服务器安装linux系统安装教程
  17. 虚拟现实未来前景无限
  18. 时间管理——永远做重要不紧急的事情
  19. 一个阿里小二“改写”了《阿里巴巴与四十大盗》 | 悦读
  20. larval中redis的用法

热门文章

  1. 优秀渗透工具资源整理(持续更新)
  2. Linux通过第三方应用提权实战总结
  3. 《剑指offer》二进制中1的个数
  4. Lucene学习总结之二:Lucene的总体架构
  5. BAT机器学习面试1000题系列(第1~10题)
  6. 利用 livy 远程提交 spark作业
  7. Bootstrap list-group-item获取值
  8. 聊聊高并发(二十八)解析java.util.concurrent各个组件(十) 理解ReentrantReadWriteLock可重入读-写锁
  9. spark MLlib平台的协同过滤算法---电影推荐系统
  10. 使用localStorage写一个简单的备忘录