HDU 5327 Olympiad(2015多校联合)


题目链接

戳我

题目大意

计算区间 \(L R\)内每个数的 每位 是由不同的数 构成的 个数
即 一个区间内的每个数 它的个位,十位.....是不同的数字构成的个数

样例解释

解题思路

简单题. 但是暴力枚举肯定会超时的.但是比赛的时候数据比较弱,可以水过去.....
可以先预处理每一个前缀有多少个即可

代码

//Author LJH
//www.cnblogs.com/tenlee
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#define clc(a, b) memset(a, b, sizeof(a))
using namespace std;

const int inf = 0x3f;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+5;
int a[maxn], b[maxn], ha[20];

bool judge(int n)
{
    clc(ha, 0);
    int x, y;
    while(n)
    {
        x = n % 10;
        n = n / 10;
        if(ha[x]) return false;
        else ha[x] = 1;
    }
    return true;
}
void Init()
{
    clc(b, 0);
    a[0] = 1;
    for(int i = 1; i < maxn; i++)
    {
        a[i] = a[i-1];
        if(judge(i))
        {
            b[i] = 1;
            a[i]++;
        }
    }
}

int main()
{
    Init();
    int T;
    int x, y, ans;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d %d", &x, &y);
        ans = a[y] - a[x];
        if(b[x]) 
        {
            ans++;
            //puts("hehe");
        }
        printf("%d\n", ans);
    }
}

转载于:https://www.cnblogs.com/tenlee/p/4693003.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值