Gym--100952B--New Job
来源:互联网 发布:linux grub命令行 编辑:程序博客网 时间:2024/06/08 17:52
题目
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.
Example
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.
这个题就是数字每次按2^0,2^1,2^2…将电脑数量相减
这到题不要想复杂了,就用一个if else判断,将最大能相减的数字范围作为判断条件将电脑数减为0即可
#include<cstdio>int main(){ int T,k,N,M,count; scanf("%d",&T); while(T--) { count=0; k=1; scanf("%d%d",&N,&M); while(N>0) { if(k<M) { N=N-k; k*=2; } else { N=N-M; } count++; } printf("%d\n",count); } return 0;}
- Gym--100952B--New Job
- Gym - 100625B Bribe
- CodeForces Gym 100114B
- CodeForces Gym 100735B
- Gym 100971B Derangement
- Gym 100803 B Miscalculation
- Codeforces GYM 100726B
- Gym 100623B Billboard
- Gym 101201B dp
- Gym 101389. B
- Gym 101201.B
- Bonapity Gym-101028B
- Gym 100960B B. Forcefield
- My new job
- New Job Start
- my new job
- New Job Start
- New job,Assembly Language
- Linux的第一节课
- 蓝牙nrf51822空中升级
- ORA-01654 问题解决
- 百度地图批量顺序转换经纬度防止顺序错位
- svn环境的搭建与命令行基本使用
- Gym--100952B--New Job
- springMVC——@RequestParam
- 栈的顺序存储结构C语言
- 求最大公约数和最小公倍数
- CI脚本异常退出问题定位
- POJ 1002 487-3279
- 中间数
- 树和二叉树的实验2
- 软件工程(C编码实践篇)学习总结