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
第一次做的时候循环遍历逐个比对,时间复杂度为O(n*longn),原以为测试数据不太多,不会超时,结果还是超了。然后采取了打表的方式,用数组保存下标以内所有正整数里包含的 beatiful numbers的数量,在查询的时候用下标b对应的值减去下标a-1对应的值便是a,b之间 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;
}
- Multi-University Training Contest 4 — 1001题
- Multi-University Training Contest 4 — 1002题
- 2012 Multi-University Training Contest 4-1001 hdu4331 Image Recognition
- 2015 Multi-University Training Contest 4 1001 Olympiad
- 2016 Multi-University Training Contest 4 1001 Another Meaning
- 2016 Multi-University Training Contest 4 1001 Another Meaning (DP)
- #2017 Multi-University Training Contest 2 1001
- Multi-University Training Contest 3 — 1004题
- 2012 Multi-University Training Contest 4
- 2013 Multi-University Training Contest 4
- 2014 Multi-University Training Contest 4小记
- 2013 Multi-University Training Contest 4
- 2015 Multi-University Training Contest 4
- 2015 Multi-University Training Contest 4
- 2015 Multi-University Training Contest 4
- 2015 Multi-University Training Contest 4
- 2015 Multi-University Training Contest 4
- 2016 Multi-University Training Contest 4
- Android 百分比布局库(percent-support-lib) 解析与扩展
- 使用国内镜像通过pip安装python的一些包(转)
- HDOJ 欧拉回路 1878【欧拉回路判定】
- Multi-University Training Contest 3 — 1004题
- Android Fragment数据保存问题
- Multi-University Training Contest 4 — 1001题
- 翁恺导师第1周编程题"设计一个表示分数的Fraction类”--网易云课堂
- js使用正则(简单介绍)
- hibernate 注解
- Android蓝牙串口通信模板及demo,trick
- MySql免安装版l配置方法
- 解析json文件
- HDU 1698 Just a Hook (线段树区间更新)
- hadoop2.2.0的配置