Repeat Number
来源:互联网 发布:网易养猪场 知乎 编辑:程序博客网 时间:2024/05/16 04:23
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 1010 12
样例输出
52
提示
If a equals b, we can call a, b are Repeat Numbers too, and a is the Repeat Numbers for itself.
题意:a+b=c中c每一位数字都相同,为在x~y中有多少个这样的组合,其中数字可以重复,例如11+11==22; 题解:找到x*2和y*2中c个区间,然后暴力求解; 代码如下: #include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>#include <stdlib.h>using namespace std;int a[40];void f(){ int j,k=0; for (int i = 11; i <= 10000000; i = i*10+1) for (j = 1; j <= 9; j ++) a[k ++] = i*j;}int main (){ int n,m,i,j,k; f(); while (scanf("%d%d",&n,&m)!=EOF) { int x=-1,y=0; for (i = 0; i < 54; i ++) { if (a[i] >= n*2&& x==-1 ) x = i; if (a[i] <= m*2) { y = i; } } int sum = 0; for (i = x; i <= y; i ++) { for (j = n; j <= m; j ++) { if(a[i]-j <j) break; if (a[i]-j >= n && a[i]-j <= m && a[i]-j >= j){ sum ++; } } } printf("%d\n",sum); } return 0;}
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.
#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>#include <stdlib.h>using namespace std;int a[40];void f(){ int j,k=0; for (int i = 11; i <= 10000000; i = i*10+1) for (j = 1; j <= 9; j ++) a[k ++] = i*j;}int main (){ int n,m,i,j,k; f(); while (scanf("%d%d",&n,&m)!=EOF) { int x=-1,y=0; for (i = 0; i < 54; i ++) { if (a[i] >= n*2&& x==-1 ) x = i; if (a[i] <= m*2) { y = i; } } int sum = 0; for (i = x; i <= y; i ++) { for (j = n; j <= m; j ++) { if(a[i]-j <j) break; if (a[i]-j >= n && a[i]-j <= m && a[i]-j >= j){ sum ++; } } } printf("%d\n",sum); } return 0;}
0 0
- Repeat Number
- Repeat Number
- Repeat Number
- ZCMU-1445-Repeat Number
- 1445: Repeat Number
- 2014辽宁省赛 Repeat Number
- kuangbin群赛-1002-Repeat Number
- repeat
- Algorithm-Arrays-5 Repeat and Missing Number Array
- Repeat Part of the Regex a Certain Number of Times (重复匹配中的部分)
- background-repeat:no-repeat
- Finding a number that repeats even no of times where all the other numbers repeat odd no of times
- Repeat分页
- selective repeat
- background-repeat
- repeat嵌套
- repeat until
- Angularjs repeat
- CPU卡程序设计实例(三)命令格式
- 内核轮询式IO(poll-select)
- 百度地图开发平台范例
- 博为峰Java技术文章 ——JavaSE 如何使用窗口组件Ⅰ
- 第七章 7-5 子窗口和键盘
- Repeat Number
- vue实现webapp
- 设计模式-构建者模式
- 二叉树前序,中序,后序遍历详解
- linux与window文件共享——Samba配置详细过程
- office
- 二分贪心练习--E(牛的距离)
- 第四 管理系统中的简单分区和文件系统
- spring-batch很不错的资料