zoukankan      html  css  js  c++  java
  • POJ 3307 Smart Sister

    先找出所有的数,排序,然后o(1)效率询问

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<map>
    using namespace std;
    
    long long Ans[1200000];
    int tot;
    map<long long, int>Cun;
    const long long INF = 1e18;
    
    void init()
    {
        tot = 0;
        Cun.clear();
        Cun[1] = 1;
        Ans[tot] = 1;
    }
    
    int main()
    {
        int head = 0;
        init();
        while (1)
        {
            if (Ans[head] == 0) break;
            long long  h = Ans[head];
            if (h * 2 > INF || Cun[h * 2] == 1) {}
            else
            {
                tot++;
                Ans[tot] = h * 2;
                Cun[h * 2] = 1;
            }
    
            if (h * 3 > INF || Cun[h * 3] == 1){}
            else
            {
                tot++;
                Ans[tot] = h * 3;
                Cun[h * 3] = 1;
            }
    
            if (h * 5 > INF || Cun[h * 5] == 1) {}
            else
            {
                tot++;
                Ans[tot] = h * 5;
                Cun[h * 5] = 1;
            }
    
            if (h * 7 > INF || Cun[h * 7] == 1) {}
            else
            {
                tot++;
                Ans[tot] = h * 7;
                Cun[h * 7] = 1;
            }
            head++;
        }
        sort(Ans, Ans + tot + 1);
        int T;
        scanf("%d", &T);
        while (T--)
        {
            int n;
            scanf("%d", &n);
            printf("%lld
    ", Ans[n - 1]);
        }
        return 0;
    }
  • 相关阅读:
    Spring MVC之视图呈现
    Spring MVC之HandlerMap 初始化
    Spring MVC之DispatcherServlet请求处理
    合成模式
    缺省适配器
    适配器模式
    原始模型
    克隆 和 比较
    建造模式
    线段树
  • 原文地址:https://www.cnblogs.com/zufezzt/p/4779471.html
Copyright © 2011-2022 走看看