Repeat Number(数论)
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代码:
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- #include <math.h>
- #include <stdlib.h>
- using namespace std;
- int aa[];
- int f() // 将满足情况的c值存入数组
- {
- int i,j,k=;
- for (i = ; i < ; i=i*+)
- for (j = ; j <= ; j ++)
- aa[k ++] = i*j;
- aa[k] = ; // 不要忘记这个最大的哦(1111111 在这个最大的范围内 1000000+1000000)
- }
- int main ()
- {
- f();
- int a,b,j,i;
- while (scanf("%d%d",&a,&b)!=EOF)
- {
- int sum = ;
- for (i = ; i < ; i ++)
- {
- if (a* <= aa[i] && aa[i] <= b*) // 判断是否在[a+a,b+b]范围内
- sum += min(aa[i]/-a+,b-(aa[i]+)/+);
- }
- printf("%d\n",sum);
- }
- return ;
- }
- /*
- sum += min(aa[i]/2-a+1,b-(aa[i]+1)/2+1);
- 关于以上代码的解释:
- 举一个简单的例子 假如输入的x,y为1 10
- 只有一个11在[2,20]范围内
- 想一想那些数能够组合成11
- (1,10)(2,9)(3,8)(4,7)(5,6)这五个
- 以(5,6)这一组为分界
- (1(2(3(4(5,6)7)8)9)10)
- 假如输入的x,y为3 10
- 也只有一个11在[6,20]范围内
- 满足条件的组合
- (3,8)(4,7)(5,6)这五个
- 以(5,6)这一组为分界
- (3(4(5,6)7)8)
- 所以,根据c/2 到x和y的距离就能判断出有多少组合(选择较小值)
- */
Repeat Number(数论)的更多相关文章
- Repeat Number
Problem B: Repeat Number Time Limit: 1 Sec Memory Limit: 32 MB Description Definition: a+b = c, if ...
- 2014辽宁省赛 Repeat Number
问题 C: Repeat Number 时间限制: 1 Sec 内存限制: 128 MB [cid=1073&pid=2&langmask=0">提交][状态][论坛 ...
- WUSTOJ 1323: Repeat Number(Java)规律统计
题目链接:1323: Repeat Number Description Definition: a+b = c, if all the digits of c are same ( c is mor ...
- Leetcode 263 Ugly Number 数论 类似质因数分解
Ugly Number的质因数仅为2,3,5 将输入的数分别除以2,3,5直到不能除,看是否为1,为1的是Ugly Number,其他则不是. class Solution { public: boo ...
- 【bzoj3000】Big Number 数论
题目描述 给你两个整数N和K,要求你输出N!的K进制的位数. 输入 有多组输入数据,每组输入数据各一行,每行两个数——N,K 输出 每行一个数为输出结果. 样例输入 2 5 2 10 10 10 10 ...
- [POJ3696]The Luckiest number(数论)
题目:http://poj.org/problem?id=3696 题意:给你一个数字L,你要求出一个数N,使得N是L的倍数,且N的每位数都必须是8,输出N的位数(如果不存在输出0) 分析: 首先我们 ...
- Leetcode 9 Palindrome Number 数论
判断一个数是否是回文数 方法是将数回转,看回转的数和原数是否相同 class Solution { public: bool isPalindrome(int x) { ) return false; ...
- bzoj3000 Big Number 数论,斯特林公式
Description 给你两个整数N和K,要求你输出N!的K进制的位数. Input 有多组输入数据,每组输入数据各一行,每行两个数——N,K Output 每行一个数为输出结果 Sample In ...
- linux命令之 repeat 重复执行命令
$ vim ~/.bashrc function repeat() { number=$1 shift echo $@ for n in $(seq $number); do $@ done } $ ...
随机推荐
- Angular material mat-icon 资源参考_Av
ul,li>ol { margin-bottom: 0 } dt { font-weight: 700 } dd { margin: 0 1.5em 1.5em } img { height: ...
- ZOJ - 3939 The Lucky Week(日期循环节+思维)
Edward, the headmaster of the Marjar University, is very busy every day and always forgets the date. ...
- [转] Jenkins pipeline 中获取 exit code, stdout and stderr 返回值和输出
[From] https://issues.jenkins-ci.org/browse/JENKINS-44930 其做法是,把stdout定向到一个文件,sh 配置 returnStatus: tr ...
- 1095. Maximum Swap —— Weekly Challenge
题目限定输入是[0, 10^8],因而不用考虑负数或者越界情况,算是减小了难度. public class Solution { /** * @param num: a non-negative in ...
- Ubuntu中screen命令的使用
参考GNU's Screen 官网:GNU's Scree screen的安装 sudo apt install screen 新建窗口1)可直接通过命令screen新建一个窗口,并进入窗口.但通过这 ...
- 3dsmax2020卸载/安装失败/如何彻底卸载清除干净3dsmax2020注册表和文件的方法
3dsmax2020提示安装未完成,某些产品无法安装该怎样解决呢?一些朋友在win7或者win10系统下安装3dsmax2020失败提示3dsmax2020安装未完成,某些产品无法安装,也有时候想重新 ...
- OpenStack Neutron配置虚拟机访问外网
配置完成后的网络拓扑如下: 当前环境: X86服务器1台 Ubuntu 16.04 DevStack搭建OpenStack 网络拓扑: 外部网络:192.168.98.0/24 内部网络:10.0.0 ...
- 当页面有多个js文件时,应如何引入?
1. 我们知道如果一个页面有多个js文件,并且这些js文件有的还有依赖关系的时候,我们就要特别注意他们之间的引入顺序,否则就会报错. 如:一个js文件依赖jquery,我们就要先引入jquery,然后 ...
- Redis数据持久化机制AOF原理分析一---转
http://blog.csdn.net/acceptedxukai/article/details/18136903 http://blog.csdn.net/acceptedxukai/artic ...
- rem单位怎么使用
rem这是个低调的css单位,近一两年开始崭露头角,有许多同学对rem的评价不一,有的在尝试使用,有的在使用过程中遇到坑就弃用了.但是我对rem综合评价是用来做web app它绝对是最合适的人选之一. ...