• Gym 100952 B. New Job


    B. New Job
    time limit per test
    1 second
    memory limit per test
    64 megabytes
    input
    standard input
    output
    standard output

    This is the first day for you at your new job and your boss asks you to copy some files from one computer to other computers in an informatics laboratory. He wants you to finish this task as fast as possible. You can copy the files from one computer to another using only one Ethernet cable. Bear in mind that any File-copying process takes one hour, and you can do more than one copying process at a time as long as you have enough cables. But you can connect any computer to one computer only at the same time. At the beginning, the files are on one computer (other than the computers you want to copy them to) and you want to copy files to all computers using a limited number of cables.

    Input

    First line of the input file contains an integer T (1  ≤  T  ≤  100) which denotes number of test cases. Each line in the next T lines represents one test case and contains two integers N, M.

    N is the number of computers you want to copy files to them (1  ≤  N  ≤  1,000,000,000). While M is the number of cables you can use in the copying process (1  ≤  M  ≤  1,000,000,000).

    Output

    For each test case, print one line contains one integer referring to the minimum hours you need to finish copying process to all computers.

    Examples
    Input
    3
    10 10
    7 2
    5 3
    Output
    4
    4
    3
    一台电脑只能与另一台电脑连接,所以t*=2,当电线用完后,将以链接的电脑减去,不带复制m即可
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <cmath>
    #include <map>
    #include <vector>
    #include <algorithm>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>y?x:y)
    #define min(x,y) (x<y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define PI 3.141592653589793238462
    #define INF 0x3f3f3f3f3f
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int dp[1260];
    int a[15],t;
    int main()
    {
        ll t,n,m;
        scanf("%lld",&t);
        while(t--)
        {
            scanf("%lld%lld",&n,&m);
            n;
            ll pos=0;
            ll ans=0;
            ll cnt=1;
            for(ll i=1;;i++)
            {
                if(m<=cnt)
                {
                    cnt=m;
                    ans++;
                    pos+=cnt;
                    if(pos>=n)
                    {
                        cout<<ans<<endl;
                        break;
                    }
                    if((n-pos)%cnt==0) ans+=(n-pos)/cnt;
                    else ans+=(n-pos)/cnt+1;
                    cout<<ans<<endl;
                    break;
                }
                ans++;
                pos+=cnt;
                if(pos>=n)
                {
                    cout<<ans<<endl;
                    break;
                }
                cnt*=2;
            }
        }
        return 0;
    }
  • 相关阅读:
    核心容器的两个接口(ApplicationContext和BeanFactory)引发出的问题
    ApplicationContext的三个常用实现类:
    IDEA如何找到接口的实现类
    编写BeanFactory
    9.4 Binder系统_驱动情景分析_服务使用过程
    9.3 Binder系统_驱动情景分析_服务获取过程
    9.2 Binder系统_驱动情景分析_服务注册过程
    9.1 Binder系统_C程序示例_框架分析和编写程序
    8.6 Android灯光系统_源码分析_背光灯
    8.5 Android灯光系统_源码分析_通知灯
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7199113.html
Copyright © 2020-2023  润新知