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;
    }
     
    
  • 相关阅读:
    14_java之变量|参数|返回值|修饰符
    NYOJ 202 红黑树 (二叉树)
    NYOJ 138 找球号(二) (哈希)
    NYOJ 136 等式 (哈希)
    NYOJ 133 子序列 (离散化)
    NYOJ 129 树的判定 (并查集)
    NYOJ 117 求逆序数 (树状数组)
    NYOJ 93 汉诺塔 (数学)
    HDU 2050 折线分割平面 (数学)
    天梯赛L2-008 最长对称子串 (字符串处理)
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144209.html
Copyright © 2011-2022 走看看