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 资源参考_Places
ul,li>ol { margin-bottom: 0 } dt { font-weight: 700 } dd { margin: 0 1.5em 1.5em } img { height: ...
- python迭代、可迭代对象、迭代器及生成器
迭代 通常意义上的迭代是指:重复执行一系列运算,从前面的量依次推出后面的量的过程,每一次迭代的结果,会作为下一次迭代的初始值. 在c.c++.java等编程语言中的for循环语句,就是一个迭代过程,例 ...
- @RequestMapping 和 @RequestBody的区别
@RequestMapping要求:application/x-www-form-urlencoded 或不填 @RequestBody要求: application/json
- Docker 镜像加速
通过 Docker 官方镜像加速,中国区用户能够快速访问最流行的 Docker 镜像.该镜像托管于中国大陆,本地用户现在将会享受到更快的下载速度和更强的稳定性,从而能够更敏捷地开发和交付 Docker ...
- sql server 保留小数,向上保留指定位数的小数,仅记录,勿看。
比如 4.05 要取成 4.1 , 4.16 取成 4.2 ,4.5 取成 4.5 ,意思就是小数部分第二位不管是多少都丢掉然后加0.1,但是如果是 4.5 这样完整的就不需要处理. 可以像下面这么写 ...
- 那些H5用到的技术(4)——弹幕
前言思路实现模式无限循环模式时间线模式停止显示弹幕 前言 以前玩卷轴射击游戏的时候,大量的BOSS子弹让我们无路可逃的时候,让我见识到了真正弹幕的威力,可自从A站B站火了之后,大量评论留言参与到了视频 ...
- 使用vmware虚拟机安装linux
- android LinearLayoutForListView
由于 scrollview 套 listview 会有很多问题,网上很多人用 LinearLayout 模拟 listview, 也可以设置 adapter. 很多人直接继承 BaseAdapter, ...
- js 字符串转dom 和dom 转字符串
js 字符串转dom 和dom 转字符串 博客分类: JavaScript 前言: 在javascript里面动态创建标准dom对象一般使用: var obj = document.createE ...
- Magento 2开发教程 - 创建新模块
视频在youtube网站国内访问不了,可以使用FQ软件查看. 视频地址:www.youtube.com/embed/682p52tFcmY@autoplay=1 下面是视频文字介绍: Magento ...