HDU 5327 Olymipad (前缀和)
来源:互联网 发布:php 上传 编辑:程序博客网 时间:2024/06/11 19:45
Olympiad
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2015 Accepted Submission(s): 1262
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
2015 Multi-University Training Contest 4
Recommend
wange2014 | We have carefully selected several similar problems for you: 6253 6252 6251 6250 6249
题解: 求一个区间内的 具有(数字的每一位都不同)的这个特性的数字的个数
开出数组后,用judge() 函数判断是否符合要求,符合返回true,否则为false,在初始化的时候记录sum[i] (sum[i]代表i前符合特性的个数),有点类似打表的性质,然后就可以离线查询
一维前缀和:
这个优化 主要是用来 在O(1) 时间内求出一个序列中,a[i] +a[i-1]+……+a[j] 的和
具体原理: 用sum[i] 表示 (a[1]+a[2]+a[3]+……+a[i])其中sum[0]=0 ,则 (a[i]+a[i+1]+………+a[j]) 即等于sum[j] -sum[i-1]
#include<bits/stdc++.h>using namespace std;const int maxn=100000;int sum[maxn],T,ql,qr,rs;bool vis[10];bool judge(int num){ memset(vis,false,sizeof(vis)); while(num) { if(vis[num%10]) {return false;} vis[num%10]=true; num/=10; } return true;}void init(){ for(int i=0;i<maxn;i++) { sum[i]=judge(i)+sum[i-1]; }}int query(int n1,int n2){ return sum[n2]-sum[n1-1];}int main(){ init(); cin>>T; while(T--) { cin>>ql>>qr; rs=query(ql,qr); cout<<rs<<endl; } return 0;}
- HDU 5327 Olymipad (前缀和)
- hdu 5327 Olympiad 前缀和
- 【HDU 5327】Olympiad(前缀和)
- hdu 5327 Olympiad(前缀和)
- hdu 5480(前缀和)
- HDU 6205 前缀和
- hdu 5084 前缀和预处理
- hdu 5163 前缀和+枚举
- hdu 5183 hash+前缀和
- hdu 5044 树链剖分+前缀和
- hdu 5044 树链剖分+前缀和
- hdu 1718 Rank(前缀和)
- HDU 5480:Conturbatio 前缀和
- 【前缀和】hdu 5480 Conturbatio
- hdu 5172(RMQ+前缀和)
- HDU 5776 (sum 前缀和)
- HDU 5480 Conturbatio (前缀和)
- 前缀和 hdu 5480 (Conturbatio)
- 《机器学习实战》读书笔记
- 【机器学习】神经网络DNN的正则化
- 【matlab 异常点检测】基于欧氏距离和马氏距离的异常点检测
- 一往直前!贪心法 区间 poj 2376解题报告
- Homebrew简介和基本使用
- HDU 5327 Olymipad (前缀和)
- [调参技巧]深度机器学习中的batch的大小对学习效果有何影响?
- 属性动画+购物车+全选反选+选中计算价格+单个删除
- SQLSERVER / ORACLE 中delete/update 中的别名使用
- JSON对象调用方法
- 缓存
- 【MIUI8_6.8.18】红米NOTE3 全网通 KENZO 高通骁龙650 基于安卓L(Android 5.1) 修改精简优化版本
- Warning: Illegal offset type错误
- Mysql数据库性能调优