CodeForces 165B - Burning Midnight Oil(二分)

【中软软件测试笔试题】中国软件与技术服务股份有限公司笔试一卷 请分别写出ISO7层架构,并分别说明TCP、UDP协议分别在处于哪一层,以及TCP、 UPD协议有什么区别。 答:7 应用层 6 表示层 5 会话层 4 传输层 3网络层 2 数据链路层 1 物理层 第四层;UDP是面向无连接、不可靠数据传输协议; TCP是面向连接、可靠数据传输协议...... 阅读详情

B. Burning Midnight Oil
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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.

Sample test(s)
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.



=============================

对v的取值二分


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int n,k;

bool C(int x){
    int temp=x/k;
    int ans=x;
    if(ans>=n) return 1;
    while(temp>0)
    {
        ans+=temp;
        temp/=k;
        if(ans>=n) return 1;
    }
    return 0;
}

int bse(int n){
    int l=1,r=n;
    int ans=1;
    while (l<=r){
        int mid=l+(r-l)/2;
        if (C(mid)){
            ans=mid;
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    return ans;
}

int main()
{
    scanf("%d%d",&n,&k);
    int ans;
    if(n>k) ans=bse(n);
    else ans=bse(k);
    printf("%d\n",ans);
    return 0;
}


关于使用CMT2300A FIFO缓存区间设置为64Byte的问题 帮助你解决在使用CMT2300A 时遇到的各种问题,若有需要,请及时与我交流 阅读详情

相关推荐

遗传算法详解 附python代码实现

遗传算法 遗传算法是用于解决最优化问题的一种搜索算法。从名字来看,遗传算法借用了生物学里达尔文的进化理论:”适者生存,不适者淘汰“,将该理论以算法的形式表现出来就是遗传算法的过程。 问题引入 上面提到遗传算法是用来解决最优化问题的,下面我将以求二元函数: def F(x, y): return 3*(1-x)**2*np.exp(-(x**2)-(y+1)**2)- 10*(x/5 - x**3......

ha_ha_ha233的博客 22万+

CodeForces - 165B Burning Midnight Oil ——二分

B. Burning Midnight Oil time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day a highly important task was

Lngxling的博客 313

三极管和MOS管工作原理详解

PN结的形成 PN结是三极管以及场效应管中最基本的组成部分,要想彻底搞明白三极管以及场效应管的工作原理,必须先搞清楚PN结形成的原理和工作特性。 本征半导体以及空穴对 本征半导体(intrinsic semiconductor))完全不含杂质且无晶格缺陷的纯净半导体称为本征半导体。主要常见代表有硅、锗这两种元素的单晶体结构。硅、锗都是4价原子,在半导体内部形成相对稳定的共价键结构,如图 1所

技术交流是便宜的的博客 10万+

B. Burning Midnight Oil

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day a highly important task was commissioned to Vasya — writ

无知的我 1670

FPGA八股文(2)——笔试的FPGA问题汇总(持续更新)

常见FPGA笔试题的概念总结

居安士的博客 8907

S32K344 Bootloader实战:一个按键实现从Boot到App的无缝跳转(附完整代码)

本文详细介绍了基于NXP S32K344微控制器的Bootloader开发实战,重点解析如何通过一个硬件按键实现从Boot到App的可靠跳转。内容涵盖内存分区规划、中断向量表重映射、外设初始状态管理等核心要素,并提供了完整的代码示例和调试技巧,适用于汽车电子和工业控制等高可靠性应用场景。

weixin_29192365的博客 307

cf 165B Burning Midnight Oil

B. Burning Midnight Oil time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day a highly important task was

Clearlemon 898

属性基加密(Attribute-based Encryption, ABE)

KP-ABE中,用户的密钥定义了访问策略,密文的属性与策略进行匹配。CP-ABE中,密文定义了访问策略,用户的属性与策略进行匹配。

2201_75392924的博客 1830

Codeforces 165B Burning Midnight Oil 【二分】

题目链接:Codeforces 165B Burning Midnight OilB. Burning Midnight Oil time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output One day a highly importan

世界很大 989

分级 API Key 的使用案例

分级 API Key 的使用案例 1. 背景介绍 1.1 问题由来 随着网络服务的普及,API(Application Programming Interface,应用程序编程接口)成为了连接不同系统和应用的关键桥梁。API Key(API密钥)

欢迎来到我的优快云空间!这里聚焦AI大模型应用实战,分享前沿技术、实战案例与开发经验。 1010

服务器取证——服务器基础知识

服务器基础知识

记录并分享学习安全的知识点.. 2482

CodeForces 165B Burning Midnight Oil(二分水题)

#include #include #include #include #include #include #include #include using namespace std; const int maxn = 22222; const int maxt = 100200; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; co

fly_tzf的博客 474

YOLO创新点改进点的消融实验设计规范

YOLO改进的消融实验是一种重要的方法,用于评估和验证模型中不同组件的影响。在进行YOLO改进的消融实验时,我们可以选择一些可能的改进点,比如Backbone网络、Anchor框设计和损失函数设计,然后通过实验来分析它们对模型性能的影响。首先,我们需要确定实验设计。对于每个改进点,我们将设计多个实验组,并针对每个实验组训练模型并进行性能评估。这里以三个改进点为例进行说明:改进点1:Backbone网络 (改进点2:Anchor框设计 (改进点3:损失函数设计 (

crasher123的博客 2909

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

wjmwsgj的博客 651

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

CodeForces - 165B Burning Midnight Oil (二分)

题目链接:http://codeforces.com/problemset/problem/165/B点击打开链接 B. Burning Midnight Oil time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu

xuejye的博客 339

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

CodeForces 165B Burning Midnight Oil(二分)

题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=114355#problem/B 代码: #include #include using namespace std; __int64 n,k; int judge(__int64 x) { __int64 ans=1; __int64 kk=k; _

Pig_Me的博客 487

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

codeForces 165B.Burning Midnight Oil(二分)

题意:给你两个数字N,K。N表示有个人要写N行东西,K是跟他的写东西效率有关的额一个系数。这个人写东西写一会就累了就必须喝杯茶再写,他的效率会越来越低,V表示他第一天能写V行,然后依次能写等等,当这个值为零时他就睡着了。问你V最小为多少时,他才能写完这N行东西? 思路:二分V,

张松超的博客 514

codeforces 165B - Burning Midnight Oil codeforces 【二分+快速幂】

#include<bits/stdc++.h> #define ll long long using namespace std; ll powp(int k, int l){//快速幂 ll i, j, sum = 1; for(i = 1; i <= l; i++) { sum*=k; } return sum; } int cheak(int m, int k...

OOOak 192

CodeForces - 165B Burning Midnight Oil

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

qqchanmingdexiaji的博客 313

CodeForces 165B Burning Midnight Oil

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 

CS33sun的博客 405

Burning Midnight Oil CodeForces - 165B

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 ex

codeswarrior的博客 778

codeforces 165B Burning Midnight Oil

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34301132的博客 116

[补]CodeForces 165B Burning Midnight Oil

B. Burning Midnight Oiltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day a highly important task was commissioned to Vasya — writing a progr...

ZXM_ZhanX的博客 401

B. Burning Midnight Oil Codeforces Round 112 (Div. 2)

题目大意:最后写了至少n个,每次衰减k倍(/k),问最初的v最小为多少。 思路&方法:二分答案。

halation_Z的博客 337

B - Burning Midnight Oil CodeForces - 165B

B - Burning Midnight Oil 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 li

benniaoyizhi的博客 555
上一篇: CodeForces 160B - Unlucky Ticket
下一篇: HDU 1253 - 胜利大逃亡(三维搜索)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值