zoukankan      html  css  js  c++  java
  • 2014辽宁省赛 Repeat Number

    问题 C: Repeat Number

    时间限制1 Sec  内存限制128 MB
    提交23  解决7
    [提交][状态][论坛]

    题目描写叙述

    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.

    这道题,我是暴力加二分过的,枚举c的可能值就可以。然后求中间点与边界差的最小值就可以


    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<vector>
    using namespace std;
    vector<int> G;
    void init()
    {
        int k=1;
        for(int i=0;i<6;i++)
        {
            k=k*10+1;
            for(int j=1;j<=9;j++)
                G.push_back(k*j);
        }
    }
    int main()
    {
        int x,y;
        init();
        while(cin>>x>>y)
        {
            int p=lower_bound(G.begin(),G.end(),2*x)-G.begin();
            int q=lower_bound(G.begin(),G.end(),2*y)-G.begin();
            int ans=0;
            //for(int i=0;i<10;i++)
             //   cout<<G[i]<<endl;
            if(G[q]>2*y) q--;
           // cout<<p<<" "<<q<<endl;
            for(int i=p;i<=q;i++)
            {
                int mid = G[i]/2;
                if (mid* 2 == G[i]) ans += mid-x < y-mid ? mid-x+1 : y-mid+1;
                else ans+= mid-x+1 < y-mid ? mid-x+1 : y-mid;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    


  • 相关阅读:
    Pytorch-实战之对Himmelblau函数的优化
    Pytorch-tensor的感知机,链式法则
    Pytorch-tensor的激活函数
    Pytorch-tensor的分割,属性统计
    Pytorch-tensor的转置,运算
    Pytorch-tensor维度的扩展,挤压,扩张
    Transformer代码细节
    Leetcode 1494
    格雷码
    两个正序数组的中位数
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5115798.html
Copyright © 2011-2022 走看看