HDU - 5327 Olympiad(前缀和水题)

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)[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)T (T≤1000), indicating the number of testcases.

For each test case, there are two numbers aa and bb, as described in the statement. It is guaranteed that 1≤a≤b≤1000001≤a≤b≤100000.
Output

For each testcase, print one line indicating the answer.


题意:要你求给的范围的区间内有多少完美数  PS:完美数就是每位都不相同的数

思路:判断每位是否相同,直接排个序,然后看相邻两个数时候相同即可。范围是1-1e5,所以先直接把1-1e5的前缀和都存起来,直接找就好了。


代码:

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <cctype>
#include <sstream>
#define INF 0x3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
typedef long long LL;
using namespace std;
const int maxn = 1e5 + 5;
const LL mod = 1e9+7;

int t,a,b,d[maxn];
bool ok(int x){
    int tmp[10],cnt=0;
    while (x){
        tmp[cnt++]=x%10;
        x/=10;
    }
    sort(tmp,tmp+cnt);
    for (int i=0;i<cnt-1;i++){
        if (tmp[i]==tmp[i+1]) return 0;
    }
    return 1;
}

int main()
{
     //freopen ("in.txt","r",stdin);
     for (int i=1;i<=100000;i++){
        if (ok(i)) d[i]=d[i-1]+1;
        else d[i]=d[i-1];
     }
     scanf ("%d",&t);
     while (t--){
        scanf ("%d%d",&a,&b);
        printf ("%d\n",d[b]-d[a-1]);
     }
    return 0;
}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值