hust1600 Lucky Numbers 小水题

Lucky Numbers

Time Limit: 2 Sec   Memory Limit: 64 MB
Submissions: 189   Solved: 30

Description

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).

Input

Multiple test cases. For each test case, there is only one line consist two numbers L and R.

Output

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 С++.

Sample Input

1 48
1 484848

Sample Output

1
7

HINT



Source

Problem Setter : Yang Xiao



题意  :  某类数  只有4或者8组成   并且是48的倍数      问给定一个区间 L R   ( 1--10^15) 问区间内这种数的个数


思路:

找出所有的  这类数  查找这类数是否在区间内

#include<stdio.h>
#include<iostream>
#include<queue>
#include<set>
using namespace std;
#define ll long long
priority_queue<ll,vector<ll>,greater<ll> >que;//从小到大排列  没必要 用queue一样
ll a[70000];
void DFS(ll num,int len)//一开始这个函数搞错了  一个劲的错  哎  都怪自己不细心 代码能力也不是很强 要努力了
{
	if(len>17) return ;
	if(num%48==0) 
	  que.push(num);
    DFS(num*10+4,len+1);
	DFS(num*10+8,len+1);
}
int main()
{
      int i,n=0,cur=1,left,right;
	  ll l,r;
	  DFS(0,1);
      while(!que.empty())
	  {
           a[n++]=que.top();
		  que.pop();
	  }
	  while(scanf("%lld %lld",&l,&r)!=EOF)//由于区间很大 不好直接查找 我们可以看哪个符合条件的数在区间内
	  {
		  int cnt=0;
		 for(i=1;i<n;i++)
		   if(a[i]>=l&&a[i]<=r) cnt++;
		printf("%d\n",cnt);
	  }
	  return 0;

}


http://acm.hust.edu.cn/problem.php?id=1600

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值