CF991C Candies 二分 第十五
1 second
256 megabytes
standard input
standard output
After passing a test, Vasya got himself a box of nn candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya chooses a single integer kk, same for all days. After that, in the morning he eats kk candies from the box (if there are less than kk candies in the box, he eats them all), then in the evening Petya eats 10%10% of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats kk candies again, and Petya — 10%10% of the candies left in a box, and so on.
If the amount of candies in the box is not divisible by 1010, Petya rounds the amount he takes from the box down. For example, if there were 9797 candies in the box, Petya would eat only 99 of them. In particular, if there are less than 1010 candies in a box, Petya won't eat any at all.
Your task is to find out the minimal amount of kk that can be chosen by Vasya so that he would eat at least half of the nn candies he initially got. Note that the number kk must be integer.
The first line contains a single integer nn (1≤n≤10181≤n≤1018) — the initial amount of candies in the box.
Output a single integer — the minimal amount of kk that would allow Vasya to eat at least half of candies he got.
68
3
In the sample, the amount of candies, with k=3k=3, would change in the following way (Vasya eats first):
68→65→59→56→51→48→44→41→37→34→31→28→26→23→21→18→17→14→13→10→9→6→6→3→3→068→65→59→56→51→48→44→41→37→34→31→28→26→23→21→18→17→14→13→10→9→6→6→3→3→0.
In total, Vasya would eat 3939 candies, while Petya — 2929.
题意: 给你一个n,每次Vasya可以使数字减k,Petya可以使数字减少百分之十,问要使Vasya减去的数占一半或以上k最小是啥
k越大Vasya吃的越多,所以我们可以把1-n看作一个排好序的结果集。
在有序的集合中找最小结果可以直接二分模拟
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e5 + ;
const int mod = 1e9 + ;
typedef long long ll;
ll n;
ll check( ll x ) {
ll now, sum;
now = n, sum = ;
while( now ) {
if( now <= x ) {
sum += now;
break;
}
now -= x;
sum += x;
now -= now / ;
}
return sum;
}
int main(){
std::ios::sync_with_stdio(false);
while( cin >> n ) {
ll le = , ri = n, mid;
while( le < ri ) {
mid = ( le + ri ) / ;
if( check(mid) >= ( n + ) / ) {
ri = mid;
} else {
le = mid + ;
}
}
cout << le << endl;
}
return ;
}
CF991C Candies 二分 第十五的更多相关文章
- Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again
Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...
- java十五个常用类学习及方法举例
<code class="language-java">import java.util.Scanner; import java.util.Properties; i ...
- CF991C Candies
CF991C Candies 洛谷评测传送门 题目描述 After passing a test, Vasya got himself a box of nn candies. He decided ...
- 我的MYSQL学习心得(十五) 日志
我的MYSQL学习心得(十五) 日志 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...
- Bootstrap <基础二十五>警告(Alerts)
警告(Alerts)以及 Bootstrap 所提供的用于警告的 class.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添加一个 ...
- Bootstrap<基础十五> 输入框组
Bootstrap 支持的另一个特性,输入框组.输入框组扩展自 表单控件.使用输入框组,可以很容易地向基于文本的输入框添加作为前缀和后缀的文本或按钮. 通过向输入域添加前缀和后缀的内容,您可以向用户输 ...
- 解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译)
解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译) http://improve.dk/where-does-sql-server-store-the-sourc ...
- Senparc.Weixin.MP SDK 微信公众平台开发教程(十五):消息加密
前不久,微信的企业号使用了强制的消息加密方式,随后公众号也加入了可选的消息加密选项.目前企业号和公众号的加密方式是一致的(格式会有少许差别). 加密设置 进入公众号后台的“开发者中心”,我们可以看到U ...
- 十五个常用的jquery代码段【转】
好的文章顶一个 回到顶部按钮 通过使用 jQuery 中的 animate 和 scrollTop 方法,你无需插件便可创建一个简单地回到顶部动画: 1 // Back to top 2 $('a.t ...
随机推荐
- 我的ubuntu kylin中mentohust的使用历程
1首先下载mentohus 最新版下载(包括源码):http://code.google.com/p/mentohust/downloads/list 2打开终端(Ctrl+Alt+T) 输入sudo ...
- ansible批量管理服务 下
1 ansible-playbook 任务剧本 1.1 剧本文件概念 (1)playbook可以将多个批量操作模块功能整合,完成一件事情.(2)简化运维工作复杂度(3)playbook通过yaml语法 ...
- MyBatis 简介与入门
简介 什么是 MyBatis ? MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.My ...
- Spring cloud Feign不支持对象传参解决办法[完美解决]
spring cloud 使用 Feign 进行服务调用时,不支持对象参数. 通常解决方法是,要么把对象每一个参数平行展开,并使用 @RequestParam 标识出每一个参数,要么用 @Reques ...
- 8.源码分析---从设计模式中看SOFARPC中的EventBus?
我们在前面分析客户端引用的时候会看到如下这段代码: // 产生开始调用事件 if (EventBus.isEnable(ClientStartInvokeEvent.class)) { EventBu ...
- 算法与数据结构基础 - 位运算(Bit Manipulation)
位运算基础 说到与(&).或(|).非(~).异或(^).位移等位运算,就得说到位运算的各种奇淫巧技,下面分运算符说明. 1. 与(&) 计算式 a&b,a.b各位中同为 1 ...
- 《深入理解Java虚拟机》-(实战)练习修改class文件
这是一篇修改class文件的文章.注释并不完全,要抓住这次练习的目的: boolean在虚拟机中是以何种方式解读的 好的,开始我的表演 1.安装asmtools.jar 2.编写一个java文件,并编 ...
- ssm访问不了后台
最近整理ssm,写完demo案例,无论如何都访问不了后台,百度了好多,终于解决了问题所在 先看页面信息: 因为一直报404错误,一直找路径是不是弄错了,或配置文件弄错了,仅仅这个配置文件都看了无数遍, ...
- 网络编程网络协议篇(osi七层协议)
一 互联网的本质 咱们先不说互联网是如何通信的(发送数据,文件等),先用一个经典的例子,给大家说明什么是互联网通信. 现在追溯到八九十年代,当时电话刚刚兴起,还没有手机的概念,只是有线电话,那么此时你 ...
- (十九)c#Winform自定义控件-停靠窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...