Codeforces Burning Midnight Oil
/*
* BurningMidnightOil.cpp
*
* Created on: 2013-10-12
* Author: wangzhu
*/ /**
* 每次至少写多少行代码ret:
* 1)、当n<=k时,肯定是ret = n;
* 2)、当n > k时,则 ret>=k&ret <= n,故只需要按二分的思路将其查找一下,就可以,
* 对于每一个可能的值进行计算可以书写的代码行,之后继续,最后得到的结果就是答案
*/
#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long
LL calc(int k, int v) {
//数据容易溢出
LL sum = v, kk = k;
while (v / kk) {
sum += v / kk;
kk *= k;
}
return sum;
}
int binarySearch(int n, int k) {
LL left = k, right = n, mid = -;
while (left <= right) {
mid = left + (right - left) / ;
if (n <= calc(k, mid)) {
right = mid - ;
} else {
left = mid + ;
}
}
return (int) left;
}
int main() {
freopen("data.in", "r", stdin);
int n, k;
while (~scanf("%d%d", &n, &k)) {
if(n <= k) {
printf("%d\n",n);
continue;
} printf("%d\n", binarySearch(n, k));
}
return ;
}
Codeforces Burning Midnight Oil的更多相关文章
- B - Burning Midnight Oil CodeForces - 165B
One day a highly important task was commissioned to Vasya — writing a program in a night. The progra ...
- 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. 有一些广告非常有说服 ...
- 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. ...
- codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]
就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...
随机推荐
- 移动端web学习总结
前言: 一直想做一个移动端的阶段性学习总结,但是工作太忙总是加班.现在总算可以抽出一点时间来写一写,把知道的都写下来,这样就算忘掉了,也能很快想起来,不要太机智啊,哈哈哈! 一.移动端页面常识 1.常 ...
- SQL SERVER 主键约束
主键约束: 遵循关系型模型中的第二范式.唯一的识别一条记录,不能为空. CREATE TABLE Persons ( Id_P int NOT NULL PRIMARY KEY, LastName v ...
- 从零开始部署小型企业级虚拟桌面 -- Vmware Horizon View 6 For Linux VDI -- 结构规划
环境说明 注,本套环境所用机器全部是64位的. 管理服务器载体:安装win7操作系统,通过VMware Workstation安装4台虚拟机,用作vCenter,Connection Server,D ...
- ODBC连接MySQL出现"E_FAIL"错误
ODBC不能处理这种格式的数据:0000-00-00,将其更新为正常的时间即可解决
- Java使用Flying Saucer实现HTML代码生成PDF文档
1.需要的jar包:org.xhtmlrenderer.flying-saucer-pdf-itext5,Maven依赖如下: <dependency> <groupId>or ...
- PHP学习笔记——上传文件到服务端的文件夹下
环境 开发包:appserv-win32-2.5.10 服务器:Apache2.2 数据库:phpMyAdmin 语言:php5,java 平台:windows 10 需求 编写一个PHP脚本页面,可 ...
- C/C++代码检视要点
4.1.1 C/C++代码检视要点 代码检视技能属于开发人员的基本功,能够很大程度地反应出开发人员的能力水平,前面4.4.1节已经讲过提高评审检视的方法.下面以实际的C/C++语言方面的代 ...
- javascripct流程语句
1.条件选择 if 语句:只有当指定条件为true时,使用该语句来执行代码 if...else语句:当条件为true时执行代码,当条件为 false 时执行其他代码 if...else i ...
- STM32F407移植contiki2.6后使用LWIP库实现tcp client
最近在做智能家居,物联网项目,用到了C下的contiki移植 经过一阵调试,终于在 STM32F407移植contiki2.6后使用LWIP库实现tcp client. 一路艰辛谁人知道....唯有留 ...
- django引用static目录下的css,js文件304问题
前提:django1.8 在html页面可以请求道css,js文件并在chrome的开发者工具中查看css,js文件返回状态为200 原因: html页面在头部添加了<!DOCTYPE html ...