AtCoder

题目链接:https://vjudge.net/problem/AtCoder-4276

题目大意:给你一个数,让你找比他小而且只有3,5,7三个数字组成且每种数字都大于1的数的数量

  本题的数据范围不大,最多只有1e9,所以真男人就要大力搜(, 枚举每一位的所有情况就行了,最慢也就O(3^10)

#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '
'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("==================================================
")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e3+10;
ll num, ans;
void dfs(ll x, int n3, int n5, int n7) {
    if (x>num) return;
    if (x<=num && n3>=1 && n5>=1 && n7>=1) ++ans;
    dfs(x*10+3, n3+1, n5, n7);
    dfs(x*10+5, n3, n5+1, n7);
    dfs(x*10+7, n3, n5, n7+1);
}
int main(void) {
    while(~scanf("%lld", &num)) {
        ans = 0;
        dfs(0, 0, 0, 0);
        printf("%lld
", ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/shuitiangong/p/12486010.html