Repeat Number

1614: Repeat Number

时间限制: 1 Sec  内存限制: 32 MB
提交: 134  解决: 39
[提交][状态][讨论版]

题目描述

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].

输入

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.

输出

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

样例输入

1 10
10 12

样例输出

5
2

提示

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

暴力是会T 的,正确的做法是先预处理,即打表。x+y=a[i],那么x的个数为a[i]/2-x+1。但是这样会WA,没有考虑全面,x+y=a[i]有a[i]/2种组合,但是我们应该取【x,a[i]/2】,【a[i]/2,y】两者区间的最小值,才能保证x,y都在题目所给的区间范围内。

#include<bits/stdc++.h>
using namespace std;
int a[100],n;
void init()
{
    n=0;
    for(int i=1;i<=9;i++)
    {
        int s=i*10+i;
        a[n++]=s;
        while(s<=2000000)
        {
            s=s*10+i;
            a[n++]=s;
        }
    }
    sort(a,a+n);
}
int main()
{
    init();
    int x,y;
    while(scanf("%d%d",&x,&y)==2)
    {
        if(y*2<a[0]||x*2>a[n-1])
        {
            printf("0\n");
            continue;
        }
        int ans=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]>=x*2&&a[i]<=y*2)
                ans+=min(a[i]/2-x+1,y-(a[i]+1)/2+1);
        }
        printf("%d\n",ans);
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值