题目链接:Codeforces 165B Burning Midnight Oil

B. Burning Midnight Oil
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: first he writes v lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , …

The expression is regarded as the integral part from dividing number a by number b.

The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.

Vasya is wondering, what minimum allowable value v can take to let him write not less than n lines of code before he falls asleep.

Input
The input consists of two integers n and k, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1 ≤ n ≤ 109, 2 ≤ k ≤ 10.

Output
Print the only integer — the minimum value of v that lets Vasya write the program in one night.

Examples
input
7 2
output
4
input
59 9
output
54
Note
In the first sample the answer is v = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.

In the second sample the answer is v = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that’s even more than n = 59.

题意:有n的作业量,现在一个人第1次完成v的作业量,第二次完成v / k的作业量,第三次完成v / (k*k)的作业量,直到作业量为0停止。问你最小的v。

就是一个二分,脑残还WA一次。

AC代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#define CLR(a, b) memset(a, (b), sizeof(a))
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 2*1e5 +10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
void add(LL &x, LL y) { x += y; x %= MOD; }
bool judge(LL o, LL k, LL n) {LL ans = o;LL b = k;if(ans >= n) return true;while(o >= b) {ans += o / b;b = b * k;}return ans >= n;
}
int main()
{LL n, k;while(scanf("%lld%lld", &n, &k) != EOF) {LL l = 0, r = n, ans;while(r >= l) {LL mid = (l + r) >> 1;if(judge(mid, k, n)) {ans = mid;r = mid - 1;}else {l = mid + 1;}}printf("%lld\n", ans);}return 0;
}

Codeforces 165B Burning Midnight Oil 【二分】相关推荐

  1. codeforces 165B(Burning Midnight Oil)

    [题意描述] 本题就是给定代码任务为n行,起始代码书写能力为v行,然后每经过一次除以k,当v变为0时看是否完成代码任务n?并求出最小的v. [解题思路] 我们可以对v值进行二分,然后确定最后的v值. ...

  2. Burning Midnight Oil

    二分 注意细节: n<k时 i会不会溢出 #include <stdio.h> #include <stdlib.h>int main() {int n,k,sum,i, ...

  3. Educational Codeforces Round 64 -C(二分)

    题目链接:https://codeforces.com/contest/1156/problem/C 题意:给出n个数和整形数z,定义一对数为差>=z的数,且每个数最多和一个数组成对,求最多有多 ...

  4. Codeforces 484B Maximum Value(高效+二分)

    题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...

  5. CodeForces - 645C Enduring Exodus(二分)

    题目链接:http://codeforces.com/problemset/problem/645/C 题意:给你n个房间, 0代表空房子, 1代表非空的房子, 一个农夫和他的k个牛要住进空房子里面, ...

  6. Codeforces 359D Pair of Numbers | 二分+ST表+gcd

    题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...

  7. codeforces 706B B. Interesting drink(二分)

    题目链接: B. Interesting drink 题意: 给出第i个商店的价钱为x[i],现在询问mi能在多少个地方买酒; 思路: sort后再二分; AC代码: #include <ios ...

  8. CodeForces - 551C GukiZ hates Boxes(二分+贪心)

    题目链接:点击查看 题目大意:给出一个长度为 n 的数列 a,表示每个位置的障碍物数量,现在有 m 个学生可以来搬走障碍物,每一秒钟可以做出的行为如下: 从位置 i 移动到位置 i + 1 从当前位置 ...

  9. CodeForces - 967D Resource Distribution(贪心+二分+构造)

    题目链接:点击查看 题目大意:给出 n 个机器,每个机器可以处理 a[ i ] 的工作,现在有两个工作需要处理,工作量分别为 x1 和 x2,可以将一个工作分配给 k 个机器同时完成,需要满足: k ...

最新文章

  1. Remote Direct Memory Access (RDMA)
  2. Nginx log error:client sent invalid userid cookie
  3. 电脑硬件知识学习_电脑故障小知识自己动手不再花冤枉钱
  4. SpringCloud微服务注册调用入门-路由网关
  5. Windows Nano Server VHD文件制作
  6. Mysql启动找不到mysql.sock文件问题(Centos7)
  7. 【FLUENT案例】04:利用DDPM+DEM模拟鼓泡流化床
  8. matlab rand求圆周率,MATLAB做投针实验求圆周率
  9. c语言 复制到编辑页面 乱码,富文本编辑器的复制word到浏览器发生乱码(vue+wangEditor)...
  10. 如何统计网页的浏览量?Gate
  11. 为帮助建筑和设施管理者满足保持社交距离的需求,Bentley 软件公司开放对 LEGION Simulator 和 OpenBuildings Station Designer 的完全访问权限,并在
  12. android google 地图路线图,Android中如何调用google地图生成路线图
  13. 幼儿园故事导入语案例_幼儿园故事教案导入语
  14. 如果使用半导体RFID读写器CK-S640-AP60E读取RI-TRP-DR2B-40的UID信息
  15. Html设置表格撑开,【CSS】表格或div被撑开的解决办法
  16. 移动端H5页面遇到的问题总结
  17. 在javaweb中将excel表格导入存放数据库
  18. python工作流引擎_工作流,活动图和Python协程(一)
  19. Java Swing打猎射击游戏编程代码下载
  20. 测试架构师必读:编码规范、开发技巧、架构画图

热门文章

  1. sqlplus 空行 结束命令
  2. Word2016自带墨迹公式转换成mathtype公式类型
  3. 达人评测 荣耀平板7和荣耀平板X7选哪个好
  4. 神兵利器系列|nessus8.8安装破解
  5. 二进制补码转换为十进制数的方法(数学层面)
  6. python 批处理压缩图片
  7. 苹果怎么测是原装屏_实心的就是原装屏,空心的就是国产屏?
  8. java中次方函数怎么用_Excel次方函数公式怎么用
  9. 如果你能看到,请你帮我一起转,转到全中国
  10. shell脚本内调用另外一个shell脚本的几种方法