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 ...
随机推荐
- vue在窗口大小改变时强制刷新组件的方法
mounted () { window.onresize = () => { return (() => { this.$forceUpdate(); })() } }
- Linux及Windows下ActiveMQ下载与安装教程
原文连接:(http://www.studyshare.cn/blog-front//blog/details/1170/0 )一.下载 Windows: 1.官网下载地址:这里 2.百度网盘下载:这 ...
- ceph log机制
Log 是每个项目必须的,他是跟踪问题的最直接的依据.Ceph 也设计自己的log机制. 初始化启动log实例,启动log线程. _log = new ceph::log::Log(&_con ...
- Android PDA扫描枪广播接搜条码并使用
在开发扫描枪扫码接收广播条码的时候,由于厂商如shit般的文档和对Anroid基础知识的缺失,走了一些弯路,以下是广播接收条码并使用的代码实现 : 1 : 动态注册广播 PDA扫描枪对扫码有强大支持, ...
- RocketMQ中Broker的刷盘源码分析
上一篇博客的最后简单提了下CommitLog的刷盘 [RocketMQ中Broker的消息存储源码分析] (这篇博客和上一篇有很大的联系) Broker的CommitLog刷盘会启动一个线程,不停地 ...
- 用jquery实现放大镜效果
----css代码--- *{margin:0;padding:0;} .showimg{position:relative;width:450px;height:420px;border:1px s ...
- 201312-2ISBN号码
问题描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字.1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”是分隔符(键盘上的减号),最后一位 ...
- 【Kubernetes 系列四】Kubernetes 实战:管理 Hello World 集群
目录 1. 创建集群 1.1. 安装 kubectl 1.1.1. 安装 kubectl 到 Linux 1.1.2. 安装 kubectl 到 macOS 1.1.3. 安装 kubectl 到 W ...
- 强烈推荐优秀的Vue UI组件库
Vue 是一个轻巧.高性能.可组件化的MVVM库,API简洁明了,上手快.从Vue推出以来,得到众多Web开发者的认可.在公司的Web前端项目开发中,多个项目采用基于Vue的UI组件框架开发,并投入正 ...
- ansible模块介绍之ios_facts
一.模块简介 收集运行IOS系统的(此处指思科的ios)的远端设备信息 二.模块参数 auth_pass #特权密码,如果参数authorize=no,则不会检索此密码,如果任务task不指定,则默认 ...