首页 > 代码库 > Repeat Number
Repeat Number
Problem B: Repeat Number
Time Limit: 1 Sec Memory Limit: 32 MBDescription
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 1010 12
Sample Output
52
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****************************************************************/
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。