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 ...
随机推荐
- JAXB - Annotations, Type Adapters: XmlJavaTypeAdapter
For some Java container types JAXB has no built-in mapping to an XML structure. Also, you may want t ...
- OAuth2集成——《跟我学Shiro》
http://jinnianshilongnian.iteye.com/blog/2038646 目前很多开放平台如新浪微博开放平台都在使用提供开放API接口供开发者使用,随之带来了第三方应用要到开放 ...
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState:
今天做项目中的支付宝功能,是在fragment中做的,在支付成功后,想切换到支付成功的页面. 结果就报错了IllegalStateException: Can not perform this act ...
- PHP 实现对象的持久层,数据库使用MySQL
http://www.xuebuyuan.com/1236808.html 心血来潮,做了一下PHP的对象到数据库的简单持久层. 不常用PHP,对PHP也不熟,关于PHP反射的大部分内容都是现学的. ...
- Jsp与servlet之间页面跳转及参数传递实例(转)
原网址:http://blog.csdn.net/ssy_shandong/article/details/9328985 11. jsp与servlet之间页面跳转及参数传递实例 分类: Java ...
- 使用grunt运行hintjs任务
最近了解一下hintjs,学习了下使用grunt运行hintjs的方法,记录下来. 1. 下载安装nodejs 2. 安装grunt命令行 npm install -g ...
- 在Linux上进行QT UI开发
在QT Creator UI编辑器上通过拖拽各种控件产生UI界面,然后点击编译/Build按钮,会自动生成对应的ui_xxxx.h的 头文件/header file. 参考: 1.Linux上使用Qt ...
- php的运行环境介绍
php软件已下载在我的百度云:页面底部有地址,如有需要欢迎下载! 一:如何让php环境运行php代码? 直接使用php软件直接运行代码文件中的php代码 在B/S结构中让Apache使用php软件运行 ...
- Qt多文档界面应用设计
使用Qt编写多文档界面(MDI)应用相当方便,主要会使用到QMdiArea和QMdiSubWindow两个类.可以查看Qt Asistant中这两个类的说明文档,里面介绍的相当详细.另外,可以搜索例程 ...
- C#基础(七)——静态类与非静态类、静态成员的区别
静态类 静态类与非静态类的重要区别在于静态类不能实例化,也就是说,不能使用 new 关键字创建静态类类型的变量.在声明一个类时使用static关键字,具有两个方面的意义:首先,它防止程序员写代码来实例 ...