URAL 1131. Copying (math)

在幼儿园中,教育软件需要迅速复制到所有计算机上。利用有限的 null-modem 数据线,我们通过直接连接来实现软件的高效传播。本文将详细阐述如何在限制条件下,用最少的时间完成所有计算机上的软件安装。

1131. Copying

Time limit: 0.25 second
Memory limit: 64 MB
A new educating program was received by the kindergarten. Of course, children have discovered it immediately and want to play with it as soon as possible. In order to let them do it the program has to be copied to all the N computers that the kindergarten had bought just before the default of 1998. At the moment the program is installed only on one computer. Other computers do not have floppy drives and are not connected with a local network. The only way to transfer information from one computerto another is to copy it using a null-modem cable (a cable that connects two computers directly). So, if the program is installed on a computer, it can be copied to some other (but only one!) computer within an hour. There are only K null-modem cables in the kindergarten. Your task is to estimate the minimal time necessary for copying the program to all the computers in the kindergarten.

Input

The only input line contains two integers separated with a space: Nand K (1 ≤ N ≤ 10 9; 1 ≤ K ≤ 10 9).

Output

You are to output the minimal time (in hours) necessary for copying of the program to all the computers.

Sample

inputoutput
8 3
4
Problem Author: Stanislav Vasilyev, Alexander Mironenko
Problem Source: VI Ural State University Collegiate Programming Contest (21.10.2001)




解析:每个接口两端只能连两台电脑,这就代表了一台电脑只能同时为一台电脑传送数据。并且每小时一台电脑。直接模拟计算即可。




AC代码:

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, k, ans;
    scanf("%d%d", &n, &k);
    for(ans = 0; (1 << ans) < k && (1 << ans) < n; ans ++) ;
    if((1 << ans) < n)
        ans += (n - (1 << ans) - 1) / k + 1;
    printf("%d\n", ans);
    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值