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 } $ ...
随机推荐
- python高级(二)—— python内置序列类型
本文主要内容 序列类型分类: (1)容器序列.扁平序列 (2)可变序列.不可变序列 列表推导式 生成器表达式 元组拆包 切片 排序(list.sort方法和sorted函数) bisect pytho ...
- list排序问题
用Collections.sort方法对list排序有两种方法第一种是list中的对象实现Comparable接口,如下: /*** 根据order对User排序*/public class User ...
- [转] Citrix XenDesktop桌面登录VM提示Citrix Web插件错误
[From] http://blog.51cto.com/xuhaili100love/1223707 [适用版本] 适用所有Citrix虚拟桌面版本 [现象描述] 使用SC登录虚拟机提示“无法访问您 ...
- python爬虫之urllib库(二)
python爬虫之urllib库(二) urllib库 超时设置 网页长时间无法响应的,系统会判断网页超时,无法打开网页.对于爬虫而言,我们作为网页的访问者,不能一直等着服务器给我们返回错误信息,耗费 ...
- MySQL数据库 053
mysql 使用: 开启服务端软件 mysqld 开启客户端软件 mysql -uroot -p mysql : 就是一个基于socket编写的c/s架构的软件 概念介绍 : 数据库服务器 : 运行数 ...
- http请求全过程
第一步:浏览器生成http请求信息(第五层) 1.分解url 当用户输入网址时,浏览器会以一定的规则分解网址, 以 http://www.cemabenteng.com/dir/index.html ...
- IO概念解析------同步异步阻塞非阻塞
各个IO Model的比较如图所示: 阻塞和非阻塞强调的是程序在等待调用结果(消息,返回值)时的状态. 阻塞调用是指调用结果返回之前,当前线程会被挂起.调用线程只有在得到结果之后才会返回.非阻塞调用 ...
- 使用Hive Rest API 连接HDInsight
以下连接是微软最新的关于HDInsight中Hive命令的RestAPI示例地址.. 使用 HDInsight .NET SDK 运行 Hive 查询 请使用接口有异常的同学检查是否使用的是下面地址中 ...
- django notes 三:Template 的查找
django 中有 2种 Template Loader django.template.loaders.filesystem.Loader django.template.loaders.app_d ...
- Win中同时安装python2和python3及SulimeText3的python IDE搭建
一.下载安装Sublime Text3,初衷是不想忍受pycharm的打开速度,想享受下飞的质感.Sublime Text3的安装已经久远,请自行google. 二.安装python2.7与pytho ...