zoukankan      html  css  js  c++  java
  • hdu 5878 I Count Two Three

    I Count Two Three

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 719    Accepted Submission(s): 380


    Problem DesI will show you the most popular board game in the Shanghai Ingress Resistance TeIt all started several months agoWe found out the home address of the enlightened agent Icount2three and decided to draw him out.Millions of missiles were detonated, but some of them failedAfter the event, we analysed the laws of failed attacks.
    It's interesting that the i -th attacks failed if and only if can be rewritten as the form of 2^a*3^b*5^c*7^dwhich a,b,c,d are non-negative integers.

    At recent dinner parties, we call the integers with the form2^a*3^b*5^c*7^d "I Count Two Three Numbers".
    A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n .
     
    Input
    The first line of input contains an integer t (1t500000), the number of test cases. test cases follow. Each test case provides one integer n (1n10^9) .
     
    Output
    For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than n .
     
    Sample Input
    10
    1
    11
    13
    123
    1234
    12345
    123456
    1234567
    12345678
    123456789
     
    Sample Output
    1
    12
    14
    125
    1250
    12348
    123480
    1234800
    12348000
    123480000
     
    Source
     
    题意:对于每一个输入的N,找一个不小于N的最小的满足条件的值(使得这个值的因子是2,3,5,7)
    思路:暴力,之后二分搜索来查找。
    AC代码:
    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int maxn = 1000000000 + 5;
    const int N_MAX =5200;
    typedef long long LL;
    //LL table[10000];
    LL a[N_MAX] = {0,1,2,3,4,5,6,7,8,9,10};
    LL p[4] = { 2,3,5,7 };
    int main() {
        int T,n;
        for (int i = 10;i < N_MAX;i++) {
            a[i] = INT_MAX;
            int k = i - 1;
            for (int j = 0;j < 4;j++) {
                while (a[k-1] * p[j]>a[i - 1])
                    k--;
                a[i] = min(a[i],a[k]*p[j]);
            }
        }
        /*int cnt = 0;
        for (LL a =1;a <maxn;a*=2) {
            for (LL b=1;a*b <maxn;b*=3) {
                for (LL c = 1;a*b*c < maxn;c *= 5) {
                    for (LL d = 1;a*b*c*d < maxn;d *= 7) {
                        table[cnt++] = a*b*c*d;
                    }
                }
            }
        }
        sort(table, table + cnt);*/
        scanf("%d",&T);
        while (T--) {
            scanf("%d",&n);
            int id=*lower_bound(a+1, a +N_MAX,n);
            printf("%d
    ", id);
        }
        
        return 0;
    }
  • 相关阅读:
    redis存储session配制方法
    thanks使用注意事项;
    mongodb sort limit和skip用法
    mongoose的用法(注:连接数据库)
    mongoose查询特定时间段文档的方法
    webworker的使用案例
    js 传参数
    redis.config翻译
    Oracle keep详解
    自学之笔记总结
  • 原文地址:https://www.cnblogs.com/ZefengYao/p/5890972.html
Copyright © 2011-2022 走看看