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 } $ ...
随机推荐
- Chrome打开网页都提示Flash Player因过期而遭到阻止
1. 运行Chrome浏览器,地址栏输入:chrome://plugins/,找到pepflashplayer.dll安装位置, 如:D:\Program Files\GoogleChromePort ...
- 三种实现日志过滤器的方式 (过滤器 (Filter)、拦截器(Interceptors)和切面(Aspect))
1.建立RequestWrapper类 import com.g2.order.server.utils.HttpHelper; import java.io.BufferedReader; impo ...
- [转] git merge 将多个commit合并为一条之--squash 选项
[FROM] https://blog.csdn.net/themagickeyjianan/article/details/80333645 1.一般的做法(直接git merge) Git相对于C ...
- Emma姐
- PIE SDK与OpenCV结合说明文档
1.功能简介 OpenCV是基于BSD许可(开源)发行的跨平台计算机视觉库,可以运行在Linux.Windows.Android和Mac OS操作系统上.它轻量级而且高效——由一系列 C 函数和少量 ...
- Ubuntu16.04+Cuda8.0+cuDNN6配置py-faster rcnn(转)
原博客地址:https://blog.csdn.net/meccaendless/article/details/79557162 0前言Faster R-CNN是任少卿2015年底推出的目标检测算法 ...
- 如何统计Visual Studio Code项目的代码行数
背景 年底到了,公司一年一度做述职报告的时间又到了,每到此时小伙伴们都想方设法的去做一些代码层面的汇总.在此交给大家个小妙招,走过路过不要错过哈,, 解决方案 使用Visual Studio Code ...
- Java - 二分法查找(尚学堂第七章数组)
import java.util.Arrays; public class TestBinarySearch { public static void main(String[] args) { in ...
- Git版本回退和撤销修改
版本回退: 在实际工作中,我们会不断对文件进行修改,然后不断提交修改到版本库里,一旦你把文件改乱了,或者误删了文件,还可以从最近的一个commit恢复,然后继续工作,而不是把几个月的工作成果全部丢失. ...
- oracle 处理锁表sql
declare --类型定义 cursor c_cur is --查询锁表进程 SELECT object_name, machine, s.sid, s.serial# FROM gv$locked ...