HUST 1600 Lucky Numbers

暴力打表。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;

long long a[10000];
long long L, R;
int tot;

void dfs(long long num, int len)
{
    if (len > 16) return;
    if (num>=1&&num<=1000000000000000&&num % 48 == 0) a[tot++] = num;
    dfs(num * 10 + 4, len + 1);
    dfs(num * 10 + 8, len + 1);
}

void init()
{
    tot = 0;
    dfs(4, 1);
    dfs(8, 1);
}

int main()
{
    init();
    while (~scanf("%lld%lld", &L, &R))
    {
        long long ans = 0;
        for (int i = 0; i < tot; i++)
            if (a[i] >= L&&a[i] <= R) ans++;
        printf("%lld\n", ans);
    }
    return 0;
}
时间: 2024-10-15 16:06:18

HUST 1600 Lucky Numbers的相关文章

[2016-04-14][codeforces][630][C][ Lucky Numbers]

时间:2016-04-14 23:12:27 星期四 题目编号:[2016-04-14][codeforces][630][C][ Lucky Numbers] 题目大意: 问n位数字以内的幸运数字有多少个 幸运数字:只含有7,8的数字 分析: 长度为i 的幸运数字,每一位有两种可能,7 , 8,那么长度为i的幸运数字总共有 $2^i$中可能 那么长度为n 以内的所有幸运数字 就是 $2^1 + 2^2 + - + 2^n$, #include<cstdio> using namespace

Lucky Numbers (easy) CodeForces - 96B

Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it

1276 - Very Lucky Numbers

   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB According to some theory 4 and 7 are lucky digits, and all the other digits are not lucky. A lucky number is a number that contains only lucky digits in decimal notation. A

hdu-5676 ztr loves lucky numbers(乱搞题)

题目链接: ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 ztr喜欢幸运数字,他对于幸运数字有两个要求 1:十进制表示法下只包含4.7 2:十进制表示法下4和7的数量相等 比如47,474477就是 而4,744,467则不是 现在ztr想知道最小的但不小于n的幸运数字是多少 输入描述 有TT(1≤T≤10?5??)组数据,

hdu 5676 ztr loves lucky numbers(dfs+离线)

Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is

hdu 5676 ztr loves lucky numbers(BC——暴力打表+二分查找)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5676 ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 594    Accepted Submission(s): 257 Problem Description ztr loves luck

hdoj ztr loves lucky numbers 5676 (dfs模拟)

ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 918    Accepted Submission(s): 389 Problem Description ztr loves lucky numbers. Everybody knows that positive integers ar

codeforces 630C - Lucky Numbers 递推思路

630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦加上前面只有7和8的情况,一共是6位.所以递推式不难写出dp[i]=pow(2,i)+dp[i-1]; 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans[56]; void init ()

C - Lucky Numbers (easy)

Problem description Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number