zoukankan      html  css  js  c++  java
  • hdu 5676 ztr loves lucky numbers 打表+二分

    ztr loves lucky numbers

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1834    Accepted Submission(s): 707


    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 super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

    One day ztr came across a positive integer n. Help him to find the least super lucky number which is not less than n.
     
    Input
    There are T(1n105) cases

    For each cases:

    The only line contains a positive integer n(1n1018). This number doesn't have leading zeroes.
     
    Output
    For each cases
    Output the answer
     
    Sample Input
    2 4500 47
     
    Sample Output
    4747 47
     
    Source

     思路:数总共没多少,打表即可,再最大的情况特判一下;

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=1e2+10,M=1e6+10,inf=1e9+10;
    const ll INF=5e17+10,mod=1e9+7;
    
    ///数组大小
    int check(ll x)
    {
        int s=0,q=0;
        while(x)
        {
            if(x%10==4)s++;
            else q++;
            x/=10;
        }
        if(s==q)return 1;
        return 0;
    }
    vector<ll>ans;
    vector<ll>::iterator it;
    void dfs(ll x)
    {
        if(x>INF)return;
        if(check(x))ans.push_back(x);
        dfs(x*10+4);
        dfs(x*10+7);
    }
    int main()
    {
        dfs(4),dfs(7);
        sort(ans.begin(),ans.end());
        int T;
        scanf("%d",&T);
        while(T--)
        {
            ll x;
            scanf("%lld",&x);
            it=lower_bound(ans.begin(),ans.end(),x);
            if(it==ans.end())
                printf("44444444447777777777
    ");
            else printf("%lld
    ",*it);
        }
        return 0;
    }
  • 相关阅读:
    CNN(卷积神经网络)入门
    基于linux vim环境python代码自动补全
    Linux 基本bash命令
    基于pytorch的CNN、LSTM神经网络模型调参小结
    深度学习中Batch size对训练效果的影响
    argparse.ArgumentParser()用法解析
    大数据学习之Hive数据仓库 20
    centOS中安装MySQL超级方便简单的方法
    大数据学习之zookeeper案例节点动态上下线感知19
    大数据学习之zookeeper客户端的命令行及API操作18
  • 原文地址:https://www.cnblogs.com/jhz033/p/6826228.html
Copyright © 2011-2022 走看看