HUST-1600 - Lucky Numbers 深搜
2016-03-12 17:21
288 查看
1600 - Lucky Numbers
时间限制:2秒 内存限制:64兆
416 次提交 115 次通过
题目描述
Isun loves digit 4 and 8 very much. He thinks a number is lucky only if the number satisfy the following conditions:
1. The number only consists of digit 4 and 8.
2. The number multiples 48.
One day, the math teacher gives Isun a problem:
Given L and R(1 <= L <= R <= 10^15), how many lucky numbers are there between L and R. (i.e. how many x satisfy L <= x <= R, x is a lucky number).
输入
Multiple test cases. For each test case, there is only one line consist two numbers L and R.
输出
For each test case, print the number of lucky numbers in one line.
Do use the %lld specifier or cin/ cout stream to read or write 64-bit integers in С++.
样例输入
1 48
1 484848
样例输出
1
7
提示
来源
Problem Setter : Yang Xiao
题意:输入两个数字,表示一个范围,求这个范围内能被48整除,并且只包含4或者8的数字的个数。
解析:构造由4和8组成的数字,判断是否能被48整除并且在输入要求的范围之内,符合条件则计数。当数字超出上界m时,需返回。
根据以上的思路,然后写成代码:
时间限制:2秒 内存限制:64兆
416 次提交 115 次通过
题目描述
Isun loves digit 4 and 8 very much. He thinks a number is lucky only if the number satisfy the following conditions:
1. The number only consists of digit 4 and 8.
2. The number multiples 48.
One day, the math teacher gives Isun a problem:
Given L and R(1 <= L <= R <= 10^15), how many lucky numbers are there between L and R. (i.e. how many x satisfy L <= x <= R, x is a lucky number).
输入
Multiple test cases. For each test case, there is only one line consist two numbers L and R.
输出
For each test case, print the number of lucky numbers in one line.
Do use the %lld specifier or cin/ cout stream to read or write 64-bit integers in С++.
样例输入
1 48
1 484848
样例输出
1
7
提示
来源
Problem Setter : Yang Xiao
题意:输入两个数字,表示一个范围,求这个范围内能被48整除,并且只包含4或者8的数字的个数。
解析:构造由4和8组成的数字,判断是否能被48整除并且在输入要求的范围之内,符合条件则计数。当数字超出上界m时,需返回。
根据以上的思路,然后写成代码:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; int cnt; void f(long long int n,long long int m,long long int sum) { if(sum%48==0&&sum<=m&&sum>=n) {cnt++;} if(sum>m) return; for(int i=1;i<=2;i++) { sum=sum*10+4*i; f(n,m,sum); sum=(sum-4*i)/10; } } int main() { long long int n,m,s1,s2; while(~scanf("%lld%lld",&n,&m)) { cnt=0; f(n,m,0); printf("%d\n",cnt); } return 0; }
相关文章推荐
- Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
- win2003分布式文件系统(dfs)配置方法[图文详解]
- win2003分布式文件系统及其部署 图文教程
- Hadoop2.6+jdk8的安装部署(1)——使用jar包安装部署【详细】
- Hadoop FS Shell
- DFS使用方法总结
- FastDFS注意事项
- 无忧技术带您预览DFS(分布式文件系统)管理控制台
- C 语言实现迷宫 DFS算法
- 一幅图弄清DFT与DTFT,DFS的关系
- HDFS---Namenode
- HDFS ---- Services startup
- POJ1523 SPF dfs
- poj1731 Orders dfs
- Surrounded Regions
- Binary Tree Zigzag Level Order Traversal,Restore IP Addresses,Word Search,Simplify Path
- DFS基础(1)
- HDU1241 Oil Deposits
- DFS算法有趣小题目
- ZOJ Problem Set - 1711 解题报告