zoukankan      html  css  js  c++  java
  • I

    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] (ab)[a,b] (a≤b). Please be fast to get the gold medal! 

    InputThe first line of the input is a single integer T (T1000)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 1ab1000001≤a≤b≤100000. 
    OutputFor each testcase, print one line indicating the answer. 

    Sample Input

    2
    1 10
    1 1000

    Sample Output

    10
    738

    题目意思:求a 到 b 中各个位数都不相同的数的个数;
    解题思路:直接算出1 到 100000 每个数到1中有多少个符合题目意思的数;打表大法好;

     1 #include <iostream>
     2 #include <string.h>
     3 #include <set>
     4 #include <math.h>
     5 using namespace std;
     6 
     7 const int MAX = 100000 + 50;
     8 int f[MAX];
     9 
    10 int DP_A(int x )
    11 {
    12     int a[10] = {0};
    13     for(int i =0;x;x/=10)
    14     {
    15         if(a[x%10])
    16             return 0;
    17         else
    18             a[x%10] = 1;
    19     }
    20     return 1;
    21 
    22 }
    23 
    24 void DP()
    25 {
    26     for(int i = 1;i <= 100000;i++)
    27     {
    28         f[i] = f[i -1] + DP_A(i);
    29     }
    30 }
    31 
    32 int main()
    33 {
    34     DP();
    35     int N;
    36     cin>>N;
    37     while(N--)
    38     {
    39         int a,b;
    40         cin>>a>>b;
    41         cout<<f[b] - f[a-1]<<endl;
    42     }
    43 
    44     return 0;
    45 }




  • 相关阅读:
    android apk 反编译
    js 读 xml 非ie 可以支持 chrome 浏览器 与 android webView
    php+mySQl 环境搭建
    Activity 生命周期
    div 隐藏 显示 占空间 不占空间
    android 异步加载
    android 文件操作
    透明 GridView 背景透明
    eclipse 版本理解
    WebKit 上的JS直接使用Java Bean
  • 原文地址:https://www.cnblogs.com/a2985812043/p/7272368.html
Copyright © 2011-2022 走看看