zoukankan      html  css  js  c++  java
  • Repeat Number

    Problem B: Repeat Number

    Time Limit: 1 Sec  Memory Limit: 32 MB

    Description

    Definition: a+b = c, if all the digits of c are same ( c is more than ten),then we call a and b are Repeat Number. My question is How many Repeat Numbers in [x,y].

    Input

    There are several test cases.

    Each test cases contains two integers x, y(1<=x<=y<=1,000,000) described above.

    Proceed to the end of file.

    Output

    For each test output the number of couple of Repeat Number in one line.

    Sample Input

    1 10
    10 12

    Sample Output

    5
    2

    HINT

    If a equals b, we can call a, b are Repeat Numbers too, and a is the Repeat Numbers for itself.

    上代码

    #include<stdio.h>
     
    int a[123]={
        11,22,33,44,55,66,77,88,99,
        111,222,333,444,555,666,777,888,999,
        1111,2222,3333,4444,5555,6666,7777,8888,9999,
        11111,22222,33333,44444,55555,66666,77777,88888,99999,
        111111,222222,333333,444444,555555,666666,777777,888888,999999,
        1111111,2222222,3333333,4444444,5555555,6666666,7777777,8888888,9999999
    };
     
    int lower_bound(int *array, int size, int key)
    {
        int first = 0, middle;
        int half, len;
        len = size;
     
        while(len > 0) {
            half = len >> 1;
            middle = first + half;
            if(array[middle] < key) {     
                first = middle + 1;          
                len = len-half-1;
            }
            else
                len = half;
        }
        return first;
    }
     
    int main()
    {
        int x,y,i,mid;
        while(~scanf("%d%d",&x,&y))
        {
            int p=lower_bound(a,54,2*x);
            int q=lower_bound(a,54,2*y);
            int ans=0;
            if(a[q]>2*y) q--;
            for(i=p;i<=q;i++)
            {
                mid = a[i]/2;
                if (a[i]%2==0)
                {
                    if(mid-x < y-mid)
                        ans+=mid-x+1;
                    else
                        ans+=y-mid+1;
                }
                else
                {
                    if(mid-x+1 < y-mid)
                        ans+=mid-x+1;
                    else
                        ans+=y-mid;
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    /**************************************************************
        Problem: 2
        User: hui
        Language: C
        Result: 正确
        Time:0 ms
        Memory:964 kb
    ****************************************************************/
  • 相关阅读:
    mac下使用brew安装mongodb
    从零构建vue+webpack (一)
    常用软件集合(2018/08/22)
    solr集群安装部署
    zookeeper集群部署
    redis集群部署
    linux 安装jdk
    zTab layui多标签页组件
    spring boot集成swagger2
    SSH客户端,FinalShell服务器管理,远程桌面加速软件,支持Windows,Mac OS X,Linux,版本2.6.3.1
  • 原文地址:https://www.cnblogs.com/suthui/p/3816278.html
Copyright © 2011-2022 走看看