zoukankan      html  css  js  c++  java
  • Google Code Jam 2010 Round 1C Problem B. Load Testing

    https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1

    Problem

    Now that you have won Code Jam and been hired by Google as a software engineer, you have been assigned to work on their wildly popular programming contest website.

    Google is expecting a lot of participants (P) in Code Jam next year, and they want to make sure that the site can support that many people at the same time. During Code Jam 2010 you learned that the site could support at least L people at a time without any errors, but you also know that the site can't yet support P people.

    To determine how many more machines you'll need, you want to know within a factor of Chow many people the site can support. This means that there is an integer a such that you know the site can support a people, but you know the site can't support a * C people.

    You can run a series of load tests, each of which will determine whether the site can support at least X people for some integer value of X that you choose. If you pick an optimal strategy, choosing what tests to run based on the results of previous tests, how many load tests do you need in the worst case?

    Input

    The first line of the input gives the number of test cases, TT lines follow, each of which contains space-separated integers LP and C in that order.

    Output

    For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of load tests you need to run in the worst case before knowing within a factor of C how many people the site can support.

    Limits

    1 ≤ T ≤ 1000.
    2 ≤ C ≤ 10.
    LP and C are all integers.

    Small dataset

    1 ≤ L < P ≤ 103.

    Large dataset

    1 ≤ L < P ≤ 109.

    Sample


    Input 
     

    Output 
     
    4
    50 700 2
    19 57 3
    1 1000 2
    24 97 2
    Case #1: 2
    Case #2: 0
    Case #3: 4
    Case #4: 2

    Explanation

    In Case #2, we already know that the site can support between 19 and 57 people. Since those are a factor of 3 apart, we don't need to do any testing.

    In Case #4, we can test 48; but if the site can support 48 people, we need more testing, because 48*2 < 97. We could test 49; but if the site can't support 49 people, we need more testing, because 24 * 2 < 49. So we need two tests.

    Solution:

    int solve(int L, int P, int C)
    {
        int tries = 0;
        for (;;) {
            if (L * pow(C, pow(2, tries)) >= P) {
                return tries;
            }
            tries++;
        }
    }
    
    int main()
    {
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
        
        int T;
        scanf("%d
    ", &T);
        if (!T) {
            cerr << "Check input!" << endl;
            exit(0);
        }
        
        for (int t = 1; t <= T; t++) {
            cerr << "solving: #" << t << " / " << T << endl;
            
            int L, P, C;
            scanf("%d %d %d
    ", &L, &P, &C);
            auto result = solve(L, P, C);
            printf("Case #%d: %d
    ", t, result);
        }
        
        fclose(stdin);
        fclose(stdout);
        return 0;
    }
  • 相关阅读:
    Android Context
    Java 字节数组 对比 低速 指针快速
    private、protected、public、published 访问限制(或者叫类成员的可见性)
    读“变革中的思索”
    微软全球资深副总裁张亚勤先生力作——《变革中思索》连载
    这个冬天,我以《监控》下酒
    震撼 中国的史蒂芬金——读小说《监控》有感
    《监控》新派惊悚职场小说
    鱼与飞鸟的距离
    博文视点大讲堂第21期免费讲座:解密Google、百度——搜索引擎揭秘
  • 原文地址:https://www.cnblogs.com/fatlyz/p/3679002.html
Copyright © 2011-2022 走看看