Multi-University Training Contest 4 — 1001题

来源:互联网 发布:办公室平台软件 编辑:程序博客网 时间:2024/05/21 04:16

Multi-University Training Contest 4  — 1001

Olympiad

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 10    Accepted Submission(s): 8

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

21 101 1000

 

 

Sample Output

10738

 

 

题目大意:

一个数,若它的每一位上的数字都不相同,则这个数被称为 beatiful numbers 。现在给定一个区间,求其中有多少个 beatiful numbers

第一次做的时候循环遍历逐个比对,时间复杂度为On*longn),原以为测试数据不太多,不会超时,结果还是超了。然后采取了打表的方式,用数组保存下标以内所有正整数里包含的 beatiful numbers的数量,在查询的时候用下标b对应的值减去下标a-1对应的值便是ab之间 beatiful numbers的数量。

 

#include<iostream>

#include<string.h>

using namespace std;

bool judge(char *a)

{

bool wuchongfu = true;

for (int i= 0; i < strlen(a); i++)

{

if (wuchongfu == false)

break;

for (int j = i+1; j < strlen(a); j++)

{

if (a[i] == a[j] )

wuchongfu = false;

}

}

return wuchongfu;

}

int jishu[100005];

int main()

{

memset(jishu, 0, sizeof(jishu));

for (int i = 1; i <= 100003; i++)

{

jishu[i] += jishu[i - 1];

char ii[10];

itoa(i, ii, 10);

if (judge(ii) == true)

jishu[i]++;

}

int t;

cin >> t;

while (t--)

{

int a, b;

scanf("%d %d", &a, &b);

int s = 0;

printf("%d\n", jishu[b]-jishu[a-1]);

}

return 0;

}

 

 

 

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 公寓房小孩读书怎么办 小学搬迁周围住户怎么办 qq空间无法回复怎么办 入职年龄不够怎么办 鱼生病了怎么办 急救 打错电话怎么办 礼仪 脚脱皮有臭味怎么办 想做淘宝手模怎么办 办模特卡被骗怎么办 上菜时台面已摆满菜怎么办 幼儿园发现疑似水痘怎么办 幼儿园孩子长水痘怎么办 穿高跟鞋大腿疼怎么办 穿高跟鞋走路难看怎么办 小妙招鞋跟响怎么办 高跟鞋子大了怎么办 高跟鞋走路很响怎么办 小妙招鞋后跟响怎么办 高跟鞋后面磨脚怎么办 穿高跟鞋崴着脚了怎么办 亚麻裤缩水了怎么办 怎么办一个人保定损点 淘宝遇到职业敲诈怎么办 三无燕窝被打假怎么办 碰上职业打假的怎么办 遇到专业打假的怎么办 手机wifi被劫持怎么办 手机网页乱跳怎么办 老公说话不算话怎么办 编曲接不到活怎么办 电表显示跳闸黄灯怎么办 硫酸铬钾中毒怎么办 门锁能扭动却打不开怎么办 防盗门保险坏了怎么办 厦门工会卡过期怎么办 阴雨天被子受潮怎么办 衣服晾臭了怎么办 喷砂机油水分离泵有油怎么办 水太烫玻璃瓶盖打不开怎么办 玻璃罐的玻璃盖打不开怎么办? 开红酒没有开瓶器怎么办