Repeat Number

题目描述:

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.

题目大意:

     输入一个范围[x,y],判断在这个范围内能够找到多少组<a,b>使得a+b=c,

     c需要满足每一位上的数全都一样并且 c > 10。

解题思路:

    先根据题目中给定的范围,将范围内所有满足条件的c存入数组。

    然后根据输入的范围求出最小范围x+x和最大范围y+y,在该范围

    内找满足条件的组合。

AC代码:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. #include <math.h>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8.  
  9. int aa[];
  10. int f() // 将满足情况的c值存入数组
  11. {
  12. int i,j,k=;
  13. for (i = ; i < ; i=i*+)
  14. for (j = ; j <= ; j ++)
  15. aa[k ++] = i*j;
  16. aa[k] = ; // 不要忘记这个最大的哦(1111111 在这个最大的范围内 1000000+1000000)
  17. }
  18. int main ()
  19. {
  20. f();
  21. int a,b,j,i;
  22. while (scanf("%d%d",&a,&b)!=EOF)
  23. {
  24. int sum = ;
  25. for (i = ; i < ; i ++)
  26. {
  27. if (a* <= aa[i] && aa[i] <= b*) // 判断是否在[a+a,b+b]范围内
  28. sum += min(aa[i]/-a+,b-(aa[i]+)/+);
  29. }
  30. printf("%d\n",sum);
  31. }
  32. return ;
  33. }
  34.  
  35. /*
  36. sum += min(aa[i]/2-a+1,b-(aa[i]+1)/2+1);
  37. 关于以上代码的解释:
  38.  
  39. 举一个简单的例子 假如输入的x,y为1 10
  40. 只有一个11在[2,20]范围内
  41. 想一想那些数能够组合成11
  42. (1,10)(2,9)(3,8)(4,7)(5,6)这五个
  43. 以(5,6)这一组为分界
  44. (1(2(3(4(5,6)7)8)9)10)
  45.  
  46. 假如输入的x,y为3 10
  47. 也只有一个11在[6,20]范围内
  48. 满足条件的组合
  49. (3,8)(4,7)(5,6)这五个
  50. 以(5,6)这一组为分界
  51. (3(4(5,6)7)8)
  52.  
  53. 所以,根据c/2 到x和y的距离就能判断出有多少组合(选择较小值)
  54. */

Repeat Number(数论)的更多相关文章

  1. Repeat Number

    Problem B: Repeat Number Time Limit: 1 Sec  Memory Limit: 32 MB Description Definition: a+b = c, if ...

  2. 2014辽宁省赛 Repeat Number

    问题 C: Repeat Number 时间限制: 1 Sec  内存限制: 128 MB [cid=1073&pid=2&langmask=0">提交][状态][论坛 ...

  3. WUSTOJ 1323: Repeat Number(Java)规律统计

    题目链接:1323: Repeat Number Description Definition: a+b = c, if all the digits of c are same ( c is mor ...

  4. Leetcode 263 Ugly Number 数论 类似质因数分解

    Ugly Number的质因数仅为2,3,5 将输入的数分别除以2,3,5直到不能除,看是否为1,为1的是Ugly Number,其他则不是. class Solution { public: boo ...

  5. 【bzoj3000】Big Number 数论

    题目描述 给你两个整数N和K,要求你输出N!的K进制的位数. 输入 有多组输入数据,每组输入数据各一行,每行两个数——N,K 输出 每行一个数为输出结果. 样例输入 2 5 2 10 10 10 10 ...

  6. [POJ3696]The Luckiest number(数论)

    题目:http://poj.org/problem?id=3696 题意:给你一个数字L,你要求出一个数N,使得N是L的倍数,且N的每位数都必须是8,输出N的位数(如果不存在输出0) 分析: 首先我们 ...

  7. Leetcode 9 Palindrome Number 数论

    判断一个数是否是回文数 方法是将数回转,看回转的数和原数是否相同 class Solution { public: bool isPalindrome(int x) { ) return false; ...

  8. bzoj3000 Big Number 数论,斯特林公式

    Description 给你两个整数N和K,要求你输出N!的K进制的位数. Input 有多组输入数据,每组输入数据各一行,每行两个数——N,K Output 每行一个数为输出结果 Sample In ...

  9. linux命令之 repeat 重复执行命令

    $ vim ~/.bashrc function repeat() { number=$1 shift echo $@ for n in $(seq $number); do $@ done } $ ...

随机推荐

  1. Angular material mat-icon 资源参考_Av

    ul,li>ol { margin-bottom: 0 } dt { font-weight: 700 } dd { margin: 0 1.5em 1.5em } img { height: ...

  2. ZOJ - 3939 The Lucky Week(日期循环节+思维)

    Edward, the headmaster of the Marjar University, is very busy every day and always forgets the date. ...

  3. [转] Jenkins pipeline 中获取 exit code, stdout and stderr 返回值和输出

    [From] https://issues.jenkins-ci.org/browse/JENKINS-44930 其做法是,把stdout定向到一个文件,sh 配置 returnStatus: tr ...

  4. 1095. Maximum Swap —— Weekly Challenge

    题目限定输入是[0, 10^8],因而不用考虑负数或者越界情况,算是减小了难度. public class Solution { /** * @param num: a non-negative in ...

  5. Ubuntu中screen命令的使用

    参考GNU's Screen 官网:GNU's Scree screen的安装 sudo apt install screen 新建窗口1)可直接通过命令screen新建一个窗口,并进入窗口.但通过这 ...

  6. 3dsmax2020卸载/安装失败/如何彻底卸载清除干净3dsmax2020注册表和文件的方法

    3dsmax2020提示安装未完成,某些产品无法安装该怎样解决呢?一些朋友在win7或者win10系统下安装3dsmax2020失败提示3dsmax2020安装未完成,某些产品无法安装,也有时候想重新 ...

  7. OpenStack Neutron配置虚拟机访问外网

    配置完成后的网络拓扑如下: 当前环境: X86服务器1台 Ubuntu 16.04 DevStack搭建OpenStack 网络拓扑: 外部网络:192.168.98.0/24 内部网络:10.0.0 ...

  8. 当页面有多个js文件时,应如何引入?

    1. 我们知道如果一个页面有多个js文件,并且这些js文件有的还有依赖关系的时候,我们就要特别注意他们之间的引入顺序,否则就会报错. 如:一个js文件依赖jquery,我们就要先引入jquery,然后 ...

  9. Redis数据持久化机制AOF原理分析一---转

    http://blog.csdn.net/acceptedxukai/article/details/18136903 http://blog.csdn.net/acceptedxukai/artic ...

  10. rem单位怎么使用

    rem这是个低调的css单位,近一两年开始崭露头角,有许多同学对rem的评价不一,有的在尝试使用,有的在使用过程中遇到坑就弃用了.但是我对rem综合评价是用来做web app它绝对是最合适的人选之一. ...