博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF991C Candies 二分 第十五
阅读量:5775 次
发布时间:2019-06-18

本文共 2824 字,大约阅读时间需要 9 分钟。

Candies
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

The first line contains a single integer nn (1n10181≤n≤1018) — the initial amount of candies in the box.

Output

Output a single integer — the minimal amount of kk that would allow Vasya to eat at least half of candies he got.

Example
input
Copy
68
output
Copy
3
Note

In the sample, the amount of candies, with k=3k=3, would change in the following way (Vasya eats first):

686559565148444137343128262321181714131096633068→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 #include 
#include
#include
#include
#include
#include
#include
#include
#include
#define debug(a) cout << #a << " " << a << endlusing namespace std;const int maxn = 1e5 + 10;const int mod = 1e9 + 7;typedef long long ll;ll n;ll check( ll x ) { ll now, sum; now = n, sum = 0; while( now ) { if( now <= x ) { sum += now; break; } now -= x; sum += x; now -= now / 10; } return sum;}int main(){ std::ios::sync_with_stdio(false); while( cin >> n ) { ll le = 1, ri = n, mid; while( le < ri ) { mid = ( le + ri ) / 2; if( check(mid) >= ( n + 1 ) / 2 ) { ri = mid; } else { le = mid + 1; } } cout << le << endl; } return 0;}

 

转载于:https://www.cnblogs.com/l609929321/p/9225689.html

你可能感兴趣的文章
PAT A1030 动态规划
查看>>
自制一个 elasticsearch-spring-boot-starter
查看>>
软件开发学习的5大技巧,你知道吗?
查看>>
java入门第二季--封装--什么是java中的封装
查看>>
【人物志】美团前端通道主席洪磊:一位产品出身、爱焊电路板的工程师
查看>>
一份关于数据科学家应该具备的技能清单
查看>>
机器学习实战_一个完整的程序(一)
查看>>
Web框架的常用架构模式(JavaScript语言)
查看>>
如何用UPA优化性能?先读懂这份报告!
查看>>
这些Java面试题必须会-----鲁迅
查看>>
Linux 常用命令
查看>>
NodeJS 工程师必备的 8 个工具
查看>>
CSS盒模型
查看>>
ng2路由延时加载模块
查看>>
使用GitHub的十个最佳实践
查看>>
全面了解大数据“三驾马车”的开源实现
查看>>
脱离“体验”和“安全”谈盈利的游戏运营 都是耍流氓
查看>>
慎用!BLEU评价NLP文本输出质量存在严重问题
查看>>
基于干净语言和好奇心的敏捷指导
查看>>
Node.js 2017企业用户调查结果发布
查看>>