• 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
    Note

    In the first test case there are 10 computer and 10 cables. The answer is 4 because in the first hour you can copy files only to 1 computer, while in the second hour you can copy files to 2 computers. In the third hour you can copy files to 4 computers and you need the fourth hour to copy files to the remaining 3 computers.

    这道题找规律,如果没有超过M的话,它每次都是翻倍,超过的话就按照M来算,也不继续翻倍了。

    下面是AC代码:21:12:44

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 int main(){
     8     int n;
     9     scanf("%d",&n);
    10     while(n--){
    11         int a,b;
    12         scanf("%d%d",&a,&b);
    13         int h=1,i;
    14         for(i=0;a>0;i++){
    15             if(h>=b){
    16                 a-=b;
    17             }else{
    18                 a-=h;
    19                 h=h*2;
    20             }
    21         }
    22         printf("%d
    ",i);
    23     }
    24     return 0;
    25 }

     

                    

  • 相关阅读:
    MapReduce TFIDF 案列
    MapReduce PageRank案列
    MapReduce好友推荐案例
    MapReduce天气查询实列
    MapReduce源码分析
    Tiny6410之LED裸机驱动
    Linux -- objdump (待继续完善)
    Linux -- xxd 整理自man 手册 (MARK)
    Linux -- xxd (转)
    tar -- 打包压缩文件
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7208028.html
Copyright © 2020-2023  润新知