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. ...
随机推荐
- Spring基于Java的JSR-250注解
以下内容引用自http://wiki.jikexueyuan.com/project/spring/annotation-based-configuration/spring-jsr250-annot ...
- 多线程调用COM组件的体会(CoInitialize)
调用任何COM组件之前,你必须首先初始化COM套件环境,即调用CoInitialize或CoInitializeEx.COM套件环境在线程的生存周期内有效,线程退出前需要调用CoUninitializ ...
- 搜索引擎keyword智能提示的一种实现
问题背景 搜索关键字智能提示是一个搜索应用的标配.主要作用是避免用户输入错误的搜索词,并将用户引导到相应的关键词上,以提升用户搜索体验. 美团CRM系统中存在数以百万计的商家,为了让用户高速查找到目标 ...
- 同步定制 Unity团队 程序的C#文件模板
孙广东 2015.7.30 就是把程序制定好的模板(不论什么人能够更改并同步git)放到,unity项目的Editor 目录下, 当程序新建一个C#脚本后就是这个模板了. "81-C# ...
- js中window.onload 与 jquery中$(document.ready()) 測试
js中window.onload 与 jquery中$(document.ready())差别,验证代码例如以下(调换js代码和Jquer代码书写顺序測试.执行结果一样.因此与代码书写位置没关系): ...
- Python筛选法(算出十亿之内所有的质数之和)
其实别人写的挺好的了....直接上链接吧http://blog.csdn.net/power721/article/details/8216619
- Matlab遗传算法优化问题求解的演示样例代码
代码例如以下: function m_main() clear clc Max_gen = 100;% 执行代数 pop_size = 100;%种群大小 chromsome = 10;%染色体的长度 ...
- 《TCP/IP具体解释》读书笔记(22章)-TCP的坚持定时器
TCP通过让接收方指明希望从发送方接收的数据字节数(即窗体大小)来进行流量控制. 假设窗体大小为0会发生什么情况呢?这将有效阻止发送方传送数据,直到窗体变为非0为止. ACK的传输并不可靠,也就是说, ...
- Windows下编译DCMTK
原帖地址:http://www.cnblogs.com/yinxufeng/p/3636241b7084b0340cc56fd37f9e2fd8.html 下载源码生成VS项目工程编译源码 下载源码 ...
- [JS进阶] HTML5 之文件操作(file)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/oscar999/article/details/37499743 前言 在 HTML 文档中 < ...