博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Gym100952 B. New Job (2015 HIAST Collegiate Programming Contest)
阅读量:5010 次
发布时间:2019-06-12

本文共 2177 字,大约阅读时间需要 7 分钟。

 
 
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.

 

题意就是复印文件,电缆有限,然后就是在电缆数允许的情况下1台电脑复印之后就有2台电脑可以继续进行复印,然后就是4台。。。达到电缆数所允许的最大值的时候剩下的就是按电缆数进行复印。

ヾ(。`Д´。),写这个题的时候智商不在家,wa了好几次。

 

代码:

1 #include
2 using namespace std; 3 int main(){ 4 int t,n,m,i,cnt,ans; 5 scanf("%d",&t); 6 while(t--){ 7 scanf("%d%d",&n,&m); 8 cnt=1; 9 for(i=0;n>0;i++){ 10 if(cnt>m)n-=m; 11 else{ 12 n-=cnt; 13 cnt*=2; 14 } 15 } 16 printf("%d\n",i); 17 } 18 return 0; 19 }

 

 

 

 

 

转载于:https://www.cnblogs.com/ZERO-/p/9692955.html

你可能感兴趣的文章
【转】每天一个linux命令(3):pwd命令
查看>>
merge-two-sorted-lists
查看>>
MySQL(3)
查看>>
poj1061——扩展gcd水题
查看>>
UVa400.Unix ls
查看>>
POJ 2299 Ultra-QuickSort 归并排序、二叉排序树,求逆序数
查看>>
Educational Codeforces Round 60 (Rated for Div. 2) C. Magic Ship
查看>>
Windows 2008 R2系统开机时如何不让Windows进行磁盘检测?
查看>>
Reporting Service服务SharePoint集成模式安装配置(1、虚拟机+ 2、AD域环境配置)
查看>>
WP7应用开发笔记(18) 本地化与多语言
查看>>
解决 .so文件64与32不兼容问题
查看>>
归并排序法
查看>>
【剑指offer】面试题26:复杂链表的复制
查看>>
spark开发生成EXE
查看>>
Vue 全家桶介绍
查看>>
WPF Bitmap转Imagesource
查看>>
Java compiler level does not match the version of the installed Java project facet.解决方法
查看>>
笔记_小结
查看>>
Linux lsof命令 umount U盘
查看>>
自定义Font
查看>>