天天看點

hdu 5327 Olympiad 字首和

傳送門:hdu 5327 Olympiad

題目大意

給定一個整數如果這個整數的每一位都不相同的話,就說這個數叫美麗的數,

給定一個區間,求這個區間美麗數的數量

解題

字首和試水題目,先打表,然後輸出

AC代碼

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = ;
int f[MAXN+];
bool check(int n)
{
    int tmp[];
    memset(tmp,,sizeof tmp);
    while(n)
    {
        int t = n%;
        n/=;
        tmp[t]++;
        if(tmp[t]>)
            return false;
    }
    return true;
}
int main()
{
    for(int i=;i<=MAXN;i++)
        if(check(i))
            f[i] = f[i-] + ;
        else
            f[i] = f[i-];
    int t;
    int left,right;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&left,&right);
        printf("%d\n",f[right]-f[left-]);
    }
    return ;
}