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;
    }
     
    
  • 相关阅读:
    Java集合(15)--ConcurrentHashMap源码分析
    Java集合(14)--双枢轴快速排序(DualPivotQuicksort)
    Java集合(13)--LinkedHashMap源码分析
    Java集合(12)--TreeSet源码分析
    Java集合(11)--TreeMap源码分析
    Java集合(10)--HashSet源码分析
    Java集合(9)--Collection 和 Collections
    Java集合(8)--HashMap源码分析
    day33-4用java的jdbc查看数据库中表的内容
    day33-1-1用java的jdbc添加数据库中表的内容(手动输入内容)
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144209.html
Copyright © 2011-2022 走看看