hdu 5327

Olympiad

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 564    Accepted Submission(s): 406

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

//题意:给你两个区间求区间内的美丽整数的数量  定义为:整数的每一位数不同

//区间 1 100000 所以打表查询

#include <stdio.h>
#include <string.h>

int a[100005];
int b[10];
int main()
{
    memset(a,0,sizeof(a));
    for(int i=1;i<=100000;i++)
    {
        int k=i;
        memset(b,0,sizeof(b));
        while(k)
        {

            b[k%10]++;  //将每个数用作数组的下标 如果值大于2 说明重复了
            k=k/10;
        }
        int flag=0;
        for(int k=0;k<10;k++)
        {
            if(b[k]>=2)
            {
                flag=1;;
                break;
            }
        }
        if(!flag)
            a[i]=a[i-1]+1;
        else
            a[i]=a[i-1];
    }
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        printf("%d\n",a[m]-a[n-1]);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-28 01:38:41

hdu 5327的相关文章

HDU 5327(2015多校4)-Olympiad(水题)

题目地址:HDU 5327 题意:beautiful numbers的定义:就是一个数的每一位不能有相同的数字,现在给你一个区间,让你求这区间内有多少个这样的漂亮数. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algori

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 digita

HDU 5327 Olympiad (多校)

Olympiad Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 631    Accepted Submission(s): 436 Problem Description You are one of the competitors of the Olympiad in numbers. The problem of this yea

HDU 5327 区间里由不同的数字组成的数的个数-set-(枚举)

题意:形如12345是我们要找的数,形如11是不合法的数,找出区间[a~b]里的合法数的个数,1<=a<=b<=10^5 分析:预处理,枚举从1开始到i结束的区间的合法数的个数,然后输入一个区间就输出sum[b]-sum[a-1]即可.这里借助set工具,利用它的count()函数,枚举数i,判定它是否为合法的数,方法是取它的每一位,然后在set里对这一位计数,如果 !=0,说明set里已经有相同的数字了,那么这个数就不合法,否则就插入这一位的数字. STL大法好!要善于运用 代码: #

HDU 5327 Olympiad (水题)

题意:beautiful数字定义为该数字中的十进制形式每一位都不同,给一个区间[L,R],求该区间中有多少个beautiful数字. 思路:数字不大,直接暴力预处理,再统计区间[1,i]有多少个,用cnt[R]-cnt[L-1]即可. 1 #include <bits/stdc++.h> 2 #define INF 0x7f7f7f7f 3 #define pii pair<int,int> 4 #define LL long long 5 using namespace std;

hdu 5327 Olympiad (多校联赛) ——模拟

here 题意:给你两个数,让你求出这两个数之间有多少个数,这个数满足他的每一位的数都不相同.例如 113 不满足 143 满足. 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

多校#4

1001 -> HDU 5327 Olympiad 打表签到题.开场4minFB的程度... 应该有更优化的方法,为了手速不TLE就行... = = 1002 -> HDU 5328 ZZX and Permutations AP: 等差序列 GP: 等比序列 尺取法分别求AP和GP的最长序列长度然后求最大值即可. 需要注意的是等比时最好用比例相等的方法而不要用除法,因为像如[9 6 4]这个样例会产生精度问题,如果用9*4==6*6就不会又问题啦.当然随之产生的问题是相乘的话可能造成int溢

STD 第四场 1001 1002 1004

HDU 5327 5328 5335 #include <stdio.h> #include <iostream> #include <string.h> #include <stack> #include <algorithm> #include <queue> #include <map> #include <cmath> #define eps 0.00000001 #define pi acos(-1,

hdoj 5327 Olmpiad

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5327 1 #include<stdio.h> 2 #include<cstring> 3 const int MAXN = 100010; 4 bool a[MAXN]; 5 int s[MAXN]; 6 int flag[10] = {0,1,2,3,4,5,6,7,8,9}; 7 void init(){ 8 int tmp; 9 memset(a,0,sizeof(a)); 10