zoukankan      html  css  js  c++  java
  • Gym

    B. New Job

     

    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.

    模拟一下,一直复制cnt*2,当cnt>m时,一直复制m。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <cmath>
     5 #include <algorithm>
     6 #define ll long long
     7 using namespace std;
     8 
     9 int main(){
    10     int t;
    11     ll n,m;
    12     //cout << (4.1) << endl;
    13     cin>>t;
    14     while(t--){
    15         cin>>n>>m;
    16         ll ans = 0;
    17         ll cnt = 1,sum = 0;
    18         while(cnt <= m && sum < n){
    19             ans++;
    20             sum = sum + cnt;
    21             cnt = cnt*2;
    22         }
    23         if(sum >= n){
    24             cout << ans << endl;
    25             continue;
    26         }
    27         if(cnt > m){
    28             cnt = m;
    29             ll sh = n-sum;
    30             ans = ans + sh/cnt;
    31             if(sh%cnt!=0)ans++;
    32             cout << ans << endl;
    33         }
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    Linux下替换默认版本的protobuf
    论文笔记——NEURAL ARCHITECTURE SEARCH WITH REINFORCEMENT LEARNING
    kafka 学习之初体验
    git命令01
    git 命令02
    SSH远程连接连接其他主机,等待时间过长的原因。
    lsof命令详解
    文本处理命令
    Windows Server 2008 远程桌面连接拒绝
    vim文本编辑工具—修改文件内容
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7197261.html
Copyright © 2011-2022 走看看