Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】
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.
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).
For each test case, print one line contains one integer referring to the minimum hours you need to finish copying process to all computers.
3
10 10
7 2
5 3
4
4
3
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.
题目链接:http://codeforces.com/gym/100952/problem/B
题意:将一个文件复制到n台电脑上,但是只有m条网线,每台电脑一次只能连接一根网线,输出多少时间可以完成复制!
分析:模拟一下就好了!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<)
{
putchar('-');
x=-x;
}
if(x>)
{
write(x/);
}
putchar(x%+'');
}
inline ll gcd(ll x,ll p,ll mod)
{
ll cnt=;
for(;p;p>>=,x=x*x%mod)
{
if(p&)
cnt=cnt*x%mod;
}
return cnt;
}
ll n,m;
int main()
{
int t;
t=read();
while(t--)
{
ll ans=;
n=read();
m=read();
ll tim=;
while()
{
if(tim>=m)
{
tim=m;
ans+=(n/tim);
if(n%tim)
ans++;
break;
}
ans++;
n-=tim;
tim=tim*;
if(n<=)
break;
}
cout<<ans<<endl;
}
return ;
}
Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】的更多相关文章
- Gym 100952I&&2015 HIAST Collegiate Programming Contest I. Mancala【模拟】
I. Mancala time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ou ...
- Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...
- Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】
F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...
- Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】
J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...
- Gym 100952H&&2015 HIAST Collegiate Programming Contest H. Special Palindrome【dp预处理+矩阵快速幂/打表解法】
H. Special Palindrome time limit per test:1 second memory limit per test:64 megabytes input:standard ...
- Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】
G. The jar of divisors time limit per test:2 seconds memory limit per test:64 megabytes input:standa ...
- Gym 100952D&&2015 HIAST Collegiate Programming Contest D. Time to go back【杨辉三角预处理,组合数,dp】
D. Time to go back time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】
C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standar ...
- Gym 100952A&&2015 HIAST Collegiate Programming Contest A. Who is the winner?【字符串,暴力】
A. Who is the winner? time limit per test:1 second memory limit per test:64 megabytes input:standard ...
随机推荐
- HTML基础教程-简介
关于html5笔记前言 之前有在W3school学习过html5以及javascript.为了和大家一块学习,为了回顾这些遗忘的基础,现在我把之前自己整理的笔记共享给大家.希望大家共同进步. HTML ...
- 1_3 C语言解决求n!
求n!(n为键盘输入的任意整数值).要求分别用while语句和for语句实现 用while语句实现: #include <stdio.h> int main() { int n; scan ...
- [置顶]
Xamarin android中使用signalr实现即时通讯
前面几天也写了一些signalr的例子,不过都是在Web端,今天我就来实践一下如何在xamarin android中使用signalr,刚好工作中也用到了这个,也算是总结一下学到的东西吧,希望能帮助你 ...
- python中的virtualenv是干嘛的?
众所周知,python的各种库跨度比较大,比如如果你开发web的话,一个项目使用的Django是1.8, 而另一个项目使用的Django版本是1.7, 这就给开发人员带来了很大的困扰. 因此,pyth ...
- 1、opencv-2.4.7.2的安装和vs2010的配置
参考大牛们的资料,动手操作了一遍,不算太复杂,和vs2008不同,有几点需要注意,cv2.4.7.2版本没有vc9,所以无法在2008上使用(呵呵,我瞎猜的) 1.下载安装 下载http://sour ...
- Oracle添加记录的时候报错:违反完整性约束,未找到父项关键字
今天需要向一个没有接触过的一个Oracle数据库中添加一条记录,执行报错: 分析: 报错的根本原因:未找到父项关键字的原因是因为你在保存对象的时候缺失关联对象. 问题的解决思路:先保存关联对象后再保存 ...
- C# 使用 CancellationTokenSource 终止线程
http://blog.csdn.net/hezheqiang/article/details/51966511 我们在多线程中通常使用一个 C# 使用 CancellationTokenSource ...
- MySQL:表的操作 知识点难点总结:表完整性约束及其他常用知识点二次总结🙄
表操作 一 : 修改表表表表表表表表表: ALTER TABLE 语法 1. 改表名rename alter table 表名 rename 新表名 2. 增加字段add alter table 表名 ...
- IO流之字节流知识总结
IO流分为字符流和字节流. 字节流;可以读取任何文件,电脑以字节的方式储存 字符流:用来读取字符. 下面是我总结的思维导图. 相关练习代码 public class Demo { @Test publ ...
- Hadoop源码篇--Client源码
一.前述 今天起剖析源码,先从Client看起,因为Client在MapReduce的过程中承担了很多重要的角色. 二.MapReduce框架主类 代码如下: public static void m ...