码迷,mamicode.com
首页 > 其他好文 > 详细

Repeat Number

时间:2014-06-30 14:59:33      阅读:508      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   代码   for   

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\n",ans);
    }
    return 0;
}
/**************************************************************
    Problem: 2
    User: hui
    Language: C
    Result: 正确
    Time:0 ms
    Memory:964 kb
****************************************************************/

 

 

Repeat Number,布布扣,bubuko.com

Repeat Number

标签:des   style   blog   color   代码   for   

原文地址:http://www.cnblogs.com/suthui/p/3816278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!