zoukankan      html  css  js  c++  java
  • AtCoder--755——dfs

    题目描述

    You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally “Seven-Five-Three numbers”) are there?

    Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

    When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.
    Constraints
    1≤N<109
    N is an integer.

    输入

    Input is given from Standard Input in the following format:

    N

    输出

    Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

    样例输入

    575

    样例输出

    4

    提示

    There are four Shichi-Go-San numbers not greater than 575: 357,375,537 and 573.

    ————————————————————————————————————————————————————————————

    #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    //#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const int maxn = 2e5 + 7;
    const int mod = 1e9 + 7;
    #define start int wuyt()
    #define end return 0
    int n,ans;
    void dfs(int sum, unsigned char ss){
        if(sum>n)
            return;
        if(ss==07)
            ans++;
        if(sum<99999999){
            dfs(sum*10+3,ss|1);
            dfs(sum*10+5,ss|2);
            dfs(sum*10+7,ss|4);
        }
    }
    start{
        /**
        ll x=read;
        if(x==7||x==5||x==3)
            printf("YES
    ");
        else
            printf("NO
    ");
        string s;
        cin>>s;
        int len=s.size();
        int ans=999;
        for(int i=0;i<=len-3;++i)
        {
            int num=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
            ans=min(abs(num-753),ans);
        }
        cout<<ans;**/
        n=read;
        dfs(0,0);
        cout<<ans;
        end;
    }
     
    
  • 相关阅读:
    记一次Cloudera中页面监控失效问题
    spark on yarn 动态资源分配报错的解决:org.apache.hadoop.yarn.exceptions.InvalidAuxServiceException: The auxService:spark_shuffle does not exist
    sparkOnYarn报错org.apache.hadoop.fs.FSDataInputStream
    记一次newApiHadoopRdd查询数据不一致问题
    记一次sparkOnyarn错误:java.lang.UnsatisfiedLinkError
    线程八大基础核心二(启动线程)
    线程八大基础核心一(创建线程的方式)
    非常时期,做好一个普通人
    哈希算法(应用场景)
    查找算法(二分查找)
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144209.html
Copyright © 2011-2022 走看看