hdu 5327 Olympiad
题目连接
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 LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
init();
int t, x, y;
scanf("%d", &t);
while(t--) {
scanf("%d %d", &x, &y);
printf("%d\n", sum[y] - sum[x - 1]);
}
return 0;
}
hdu 5327 Olympiad的更多相关文章
- HDU - 5327 Olympiad(一维前缀和)
Olympiad Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- HDU 5327 Olympiad (多校)
Olympiad Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 5327 Olympiad (水题)
题意:beautiful数字定义为该数字中的十进制形式每一位都不同,给一个区间[L,R],求该区间中有多少个beautiful数字. 思路:数字不大,直接暴力预处理,再统计区间[1,i]有多少个,用c ...
- hdoj 5327 Olmpiad
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5327 #include<stdio.h> #include<cstring> ...
- hdu 3631 Shortest Path(Floyd)
题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 返回顶部js
backToTop.js: (function () { var $backToTopEle = $('<div class="backToTop"></div& ...
- Oracle密码过期the password has expired
oracle11G新特征,半年会提醒一次修改新密码 正常情况:只要输入原先帐号密码,回车即可. 不正常情况:输入新密码帐号,回车,提示验证错误,这时就需要切换到没过期的管理员用户,高权限也行,输入 ...
- 运用Ntop监控网络流量(视频Demo)
运用Ntop监控网络流量 ____网络流量反映了网络的运行状态,是判别网络运行是否正常的关键数据,在实际的网络中,如果对网络流量控制得不好或发生网络拥塞,将会导致网络吞吐量下降.网络性能降低.通过流量 ...
- PAT1076. Forwards on Weibo(标准bfs模板)
//标准的层次遍历模板 //居然因为一个j写成了i,debug半天.....解题前一定要把结构和逻辑想清楚,不能着急动手,理解清楚题意,把处理流程理清楚再动手,恍恍惚惚的写出来自己慢慢debug吧 # ...
- cacti yum快速部署
简述:本来是编译安装的,由于编译过程中库文件关联太多,安装文件一定要有顺序性,报错太多,到了rrdtool这一步说什么都安装不过去了,由于时间问 题,选择了yum安装,对于编译安装,这个要简单多了,她 ...
- JS 随机数
function GetRandomNum(Min,Max){ var Range = Max - Min; var Rand = Math.random(); return(Min + Math.r ...
- iOS之UIAlertView的使用
UIAlertView: 1.普通使用: //普通的alert UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"title&quo ...
- Visual studio 2013 Team Foundation Server TFS2013 设置签出独占锁
摘自: http://www.cnblogs.com/52XF/p/4239056.html 以备自查 如侵权,请告知
- PUTTY使用Ctrl+s僵死的问题
算是分享个小经验吧! 一直都是使用VM+PUTTY的方式调试Linux程序,有时候在Vi中编辑了程序,Windowns下旧习难改,顺手就Ctrl+s了,尽管我知道Vi的保存是:w. 很不幸这时的PUT ...
- boost:进程管理
概述 Boost.Process提供了一个灵活的C++ 进程管理框架.它允许C++ developer可以像Java和.Net程序developer那样管理进程.它还提供了管理当前执行进程上下文.创建 ...