ACM思维题训练集合

After passing a test, Vasya got himself a box of n 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 k, same for all days. After that, in the morning he eats k candies from the box (if there are less than k candies in the box, he eats them all), then in the evening Petya eats 10% of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats k candies again, and Petya — 10% of the candies left in a box, and so on.

If the amount of candies in the box is not divisible by 10, Petya rounds the amount he takes from the box down. For example, if there were 97 candies in the box, Petya would eat only 9 of them. In particular, if there are less than 10 candies in a box, Petya won’t eat any at all.

Your task is to find out the minimal amount of k that can be chosen by Vasya so that he would eat at least half of the n candies he initially got. Note that the number k must be integer.

Input

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

Output

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

Example

Input

68

Output

3

Note

In the sample, the amount of candies, with k=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→0.

In total, Vasya would eat 39 candies, while Petya — 29.

因为是求最小的,想枚举,或者倍增,但是枚举会超时,倍增需要单调,所以不如直接二分,验证单调性。

之后可以使用二分,不过这个题看完数据就只能用log2n的复杂度过,除了优先队列,map,set,二分没有其他的算法合适,就它了。

然后没读清楚题意,题目说的是不小于,大于等于,在二分的时候没有注意check的等号。

#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
} #define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
bool check(long long k, long long sum)
{
ll a = 0, b = 0;
while (sum)
{
// cout<<a<<" "<<b<<endl;
if (sum >= k)
{
sum -= k;
a += k;
}
else
{
a += sum;
sum = 0;
}
if (sum >= 10)
{
long long tem = sum / 10;
b += tem;
sum -= tem;
}
} return a >= b; //这没等号会错//
}
int main()
{
long long sum;
read(sum);
ll l = 1, r = sum;
while (l < r)
{
ll mid = (l + r) / 2;
if (check(mid, sum))
r = mid; else l=mid+1;
}
cout<<l<<endl;
}

CF思维联系– CodeForces - 991C Candies(二分)的更多相关文章

  1. CF思维联系--CodeForces - 218C E - Ice Skating (并查集)

    题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his ...

  2. CF思维联系–CodeForces - 225C. Barcode(二路动态规划)

    ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...

  3. CF思维联系–CodeForces -224C - Bracket Sequence

    ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", ...

  4. CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)

    ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to ...

  5. CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)

    ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...

  6. CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)

    ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...

  7. CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)

    Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...

  8. codeforces 1165F1/F2 二分好题

    Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...

  9. Candies CodeForces - 991C(二分水题)

    就是二分暴力就好了 为什么要记下来 呵呵....emm你说为什么... 行吧 好吧 我一直以为我的二分出问题了 原来不是 依旧很帅 统计的时候求的减了多少次  然后用次数乘了mid 这样做会使那个人获 ...

随机推荐

  1. Fastdfs文件系统扩容

    1.简介     FastDFS文件服务器在设计时,为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式.存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是 ...

  2. Java第二十六天,多线程等待换新机制(严格执行化)

    代码: 1.老板类: package com.lanyue.day26; public class bossRunnable implements Runnable { public myLock l ...

  3. python3(二十二) oop

    """ 面向对象编程 """ __author__ = 'shaozhiqi' # 面向对象的程序设计把计算机程序视为一组对象的集合,而每个 ...

  4. MySQL锁---InnoDB行锁需要注意的细节

    前言 换了工作之后,接近半年没有发博客了(一直加班),emmmm.....今天好不容易有时间,记录下工作中遇到的一些问题,接下来应该重拾知识点了.因为新公司工作中MySQL库经常出现查询慢,锁等待,节 ...

  5. web.page.regexp用法(全网唯一)

    前言 因为这个东西“web.page.regexp”,差点把自己杀了.一点都不夸张,这将近30度的天气,办公室不开空调,又要闷,还要带着口罩,躁动的很.加上这个鬼东西“web.page.regexp” ...

  6. Web三维编程入门总结之一:WebGL与Threejs入门知识

    /*在这里对这段时间学习的3D编程知识做个总结,以备再次出发.计划分成“webgl与three.js基础介绍”.“面向对象的基础3D场景框架编写”.“模型导入与简单3D游戏编写”三个部分,其他零散知识 ...

  7. Python爬取抖音高颜值小视频

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 有趣的python PS:如有需要Python学习资料的小伙伴可以加 ...

  8. 从hfctf学习JWT伪造

    本文作者:Ch3ng easy_login 简单介绍一下什么是JWT Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519) ...

  9. PHP函数:json_last_error

    json_last_error()  - 返回 JSON 编码解码时最后发生的错误.. 说明: json_last_error ( void ) : int 参数: 无 返回值: 返回一个整型(int ...

  10. Springboot:定时任务处理(十三)

    构建一个定时任务的service接口及实现(模拟) 接口:com\applesnt\springboot\service\TaskService.java package com.applesnt.s ...