HUST 1600 Lucky Numbers
2016-03-09 09:01
411 查看
1600 - Lucky Numbers
时间限制:2秒 内存限制:64兆
401 次提交 109 次通过
题目描述
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
提示
用深搜把每个符合条件的数字找出来,打表,然后就好了
时间限制:2秒 内存限制:64兆
401 次提交 109 次通过
题目描述
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
提示
用深搜把每个符合条件的数字找出来,打表,然后就好了
#include <iostream> #include <string.h> #include <stdlib.h> #include <algorithm> #include <math.h> #include <stdio.h> using namespace std; long long int l,r; long long int ans[200005]; int cot; int count(int x) { int num=0; while(x>0) { num++; x/=10; } return num; } void dfs(long long int x,int cnt) { if(cnt>16) return; if(x%48==0) ans[cot++]=x; dfs(x*10+8,cnt+1); dfs(x*10+4,cnt+1); } int cmp(long long int x,long long int y) { return x<y; } int main() { cot=0; memset(ans,0,sizeof(ans)); dfs(4,1); dfs(8,1); while(scanf("%lld%lld",&l,&r)!=EOF) { sort(ans,ans+cot,cmp); int pos=0; for(int i=0;i<cot;i++) { if(l<=ans[i]) { pos=i; break; } } int res=0; for(int i=pos;i<cot;i++) { if(ans[i]<=r) res++; else break; } printf("%d\n",res); } return 0; }
相关文章推荐
- 紐巴倫慢跑鞋 mhnw skwb hgpx
- 泊松分布和指数分布:10分钟教程
- 增加电脑内存条需要考虑的问题及解决办法
- 初学HTML5、初入前端
- Java注解教程及自定义注解
- Java注解处理器--annotation学习四
- 学习进度总结————王烁130201218
- iTween基础之Punch(摇晃)
- 夺命雷公狗---微信开发53----网页授权(oauth2.0)获取用户基本信息接口(3)实现世界留言版
- python open mode取值组合
- 2015年大二上-数据结构-查找-2-(2)-用哈希法组织关键字
- Java中的注解是如何工作的?--annotation学习一
- 设置listview滑动自动滑动到底部
- 不通过反射在其它类中直接调用access$000方法,即:如何绕过这个检查
- HUST 1599 - Multiple(动态规划)
- 日经春秋 20160309
- HUST 1599 - Multiple(动态规划)
- C#进行Visio二次开发之文件导出及另存Web页面
- 初学HTML5、初入前端
- C#用正则表达式 获取网页源代码标签的属性或值