微软2017年预科生计划在线编程笔试第二场B题Diligent Robots

编程入门 行业动态 更新时间:2024-10-23 13:37:03

微软2017年预科生计划<a href=https://www.elefans.com/category/jswz/34/1770935.html style=在线编程笔试第二场B题Diligent Robots"/>

微软2017年预科生计划在线编程笔试第二场B题Diligent Robots

原题见链接

点击打开链接

这题一开始我也不知道怎么做,然后大致列举了几种最基本的输入,发现,如果设花x小时造机器人,那么经过小时后,会有2^(x/Q)个机器人,那么去完成N个工作所需的时间就是B = N/(2^(x/Q))向上取整个小时,那么一共话费的时间就是x+B小时,当x = 0时表示只有最一开始的机器人一直在做工作,所花时间是N小时。那么题目就可以转变成求函数y = x + ceil(N/(2^(x/Q)))   (x = 0, Q, 2Q, 3Q...)时的最小值。

最后附上我写的c/c++代码

#include<iostream>
#include<stdio.h>
#include<cmath> 
#include<string>
#include<string.h>
#include<set>
#include<map>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10; 
int main() {long long n, q, res;scanf("%lld %lld", &n, &q);if(n == 1) res = 1;else if(n == 2) res = 2;else if(n == 3) res = 3;else {res = n;long long x = q, c = 2;long long f = x + (long long)(n * 1.0 / c + 0.5);while (f < res) {res = f;x += q;c*= 2;f = x + (long long)ceil(n * 1.0 / c);} }printf("%lld\n", res);return 0;
}



更多推荐

微软2017年预科生计划在线编程笔试第二场B题Diligent Robots

本文发布于:2024-02-12 00:48:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1684718.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   微软   笔试   第二场   计划

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!