B - Burning Midnight Oil CodeForces - 165B
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
7 2
4
59 9
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.
题解:找到一个合适的值V,
【一天,一个非常重要的任务被委托给Vasya--在一个晚上写一个程序。该程序由n行代码组成。Vasya已经耗尽,所以,他的作品就像是:第一,他写道v行代码,喝一杯茶,然后他尽可能多写为线,饮料一杯茶,然后他写道线等:,,, ...
该表达式被视为从数字a除以数字b组成的组成部分。
当前值等于0 的那一刻,Vasya立即睡着了,他只在早上才醒来,当时程序应该已经完成。
Vasya很纳闷,有什么最小允许值v可以让他写不低于比ň行代码,他睡着了。】
【题析】:需要用二分查找
#include<bits/stdc++.h>
using namespace std; int main() {
long long n;
int m;
scanf("%lld %d",&n,&m);
long long v;
int flag = ;
long long vv;
long long mid;
long long left = ;
long long right = n;
long long ans = n;
while(left <= right) {
mid = (left + right) / ;
//printf("%lld %lld %lld\n",left,right,mid);
long long sum = mid;
int count = ;
long long v = m;
int vv = mid/v;
while(vv){
sum += vv;
count++;
v = v*m;
vv = mid/v;
}
if(flag == ) break;
if(sum >= n) { ans = min(ans,mid);
right = mid - ;
ans = min(ans,mid);
} else {
left = mid + ;
}
}
printf("%lld\n",ans);
return ;
}
B - Burning Midnight Oil CodeForces - 165B的更多相关文章
- Codeforces Burning Midnight Oil
/* * BurningMidnightOil.cpp * * Created on: 2013-10-12 * Author: wangzhu */ /** * 每次至少写多少行代码ret: * 1 ...
- 2016.09.14,英语,《Using English at Work》全书笔记
半个月时间,听完了ESLPod出品的<Using English at Work>,笔记和自己听的时候的备注列在下面.准备把每个语音里的快速阅读部分截取出来,放在手机里反复听. 下一阶段把 ...
- English idioms
a hot potato : speak of an issue(mostly current) which many people are talking about and which is us ...
- 英语口语练习系列-C14-常用片语
句子 1. Some ads are extremely persuasive and we find we buy products we don't really need. 有一些广告非常有说服 ...
- CSU训练分类
√√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...
- CodeForces 508C Anya and Ghosts
Anya and Ghosts Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟
C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Beta Round #14 (Div. 2) A. Letter 水题
A. Letter 题目连接: http://www.codeforces.com/contest/14/problem/A Description A boy Bob likes to draw. ...
随机推荐
- hexo博客搭建及其美化
###1.GitHub创建个人仓库 登录到GitHub,如果没有GitHub帐号,使用你的邮箱注册GitHub帐号:Build software better, together 点击GitHub中的 ...
- lombok注解
官方文档:@EqualsAndHashCode 转:https://blog.csdn.net/zhanlanmg/article/details/50392266 1. 此注解会生成equals(O ...
- 在EasyUI的DataGrid中嵌入Combobox
在做项目时,须要在EasyUI的DataGrid中嵌入Combobox,花了好几天功夫,在大家的帮助下,最终看到了它的庐山真面: 核心代码例如以下: <html> <head> ...
- http协议的相关知识
因为如今的工作设计的Web开发,因此了解了一下Http协议.在阅读了这篇文章HTTP协议具体解释(真的非常经典)后,总结了相关经常使用知识并列在此处以方便以后的查询. HTTP协议的主要特点可概括例如 ...
- 原生js 平滑滚动到页面的某个位置
window.scrollTo() 语法1: window.scrollTo(x-coord,y-coord) x-coord 是文档中的横轴坐标. y-coord 是文档中的纵轴坐标. 例子: w ...
- What to do about Eclipse's “No repository found containing: …” error messages?
As Mauro said: "you have to remove and re-add the Eclipse Project Update site, so that its meta ...
- base64和图片互转
pom.xml添加 <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --> <dependen ...
- pat1043:输出PATest
https://www.patest.cn/contests/pat-b-practise/1043 #include "stdio.h" int main() { int i, ...
- RabbitMQ常用命令、管理界面
1.运行CMD,cd切换到RabbitMQ安装目录sbin下E:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.2\sbin 执行 rabbitm ...
- shutdown的几种方式,shutdown abort的一些弊端有哪些
1.shutdown normal 正常方式关闭数据库. 2.shutdown immediate 立即方式关闭数据库. 在SVRMGRL中执行shutdown immedia ...