原题链接:http://codeforces.com/contest/991/problem/C

Candies

After passing a test, Vasya got himself a box of nnn 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" role="presentation" style="position: relative;">kkk, same for all days. After that, in the morning he eats kk k candies from the box (if there are less than k" role="presentation" style="position: relative;">kkk candies in the box, he eats them all), then in the evening Petya eats 10%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 kkk candies again, and Petya — 10%" role="presentation" style="position: relative;">10%10%10\% of the candies left in a box, and so on.

If the amount of candies in the box is not divisible by 101010, Petya rounds the amount he takes from the box down. For example, if there were 979797 candies in the box, Petya would eat only 999 of them. In particular, if there are less than
10" role="presentation" style="position: relative;">101010 candies in a box, Petya won’t eat any at all.

Your task is to find out the minimal amount of kkk that can be chosen by Vasya so that he would eat at least half of the n" role="presentation" style="position: relative;">nnn candies he initially got. Note that the number kkk must be integer.

Input

The first line contains a single integer n" role="presentation" style="position: relative;">nnn (1≤n≤1018)(1≤n≤1018)(1≤n≤10^{18}) — the initial amount of candies in the box.

Output

Output a single integer — the minimal amount of kkk 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" role="presentation" style="position: relative;">k=3k=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→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 393939 candies, while Petya — 292929.

题解

因为每次糖果都会缩水10%10%10\%,1018101810^{18}只要300300300多次就没了,那么就愉快的二分答案吧,复杂度O(log2n×log1091018)O(log2n×log1091018)O(log_2n\times log_{\frac{10}{9}}10^{18})。

代码
#include<bits/stdc++.h>
using namespace std;
long long n,le,ri,mid;
bool check(long long k)
{long long less=0,res=n;for(;res>0;res-=k,less+=(res>0?res:0)/10,res-=res/10);return less<=n/2;
}
void in(){scanf("%I64d",&n);}
void ac()
{le=1,ri=n/2+1;while(le^ri)mid=le+ri>>1,check(mid)?ri=mid:le=mid+1;printf("%I64d",le);
}
int main(){in();ac();}

CF991C Candies相关推荐

  1. K - Candies POJ - 3159(利用了自定义比较操作符)

    K - Candies POJ - 3159 题意: 孩子 A 觉得 B 得到的糖果不能比自己多超过 c,求 n 比 1 最多能多几颗糖果 思路:DJ,松弛条件: sweet[A] > swee ...

  2. AtCoder Beginner Contest 215 G - Colorful Candies 2

    AtCoder Beginner Contest 215 G - Colorful Candies 2 有n个糖果,每个糖果有着一个颜色a[i],每次拿k个糖果期望拿到E(x)个不同颜色的糖果,求出k ...

  3. 575. Distribute Candies 平均分糖果,但要求种类最多

    [抄题]: Given an integer array with even length, where different numbers in this array represent diffe ...

  4. 1431. Kids With the Greatest Number of Candies

    Title 给你一个数组 candies 和一个整数 extraCandies ,其中 candies[i] 代表第 i 个孩子拥有的糖果数目. 对每一个孩子,检查是否存在一种方案,将额外的 extr ...

  5. HDU - 6126 Give out candies

    Give out candies 题解: 第一次遇见这样处理的网络流模型. 将问题转换成最小割问题. 具体的题解参考自:传送门 先将每个人的拆成m个人. 然后s向第1人连边流量为inf.第i个人向第i ...

  6. CF思维联系– CodeForces - 991C Candies(二分)

    ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...

  7. poj 2886 Who Gets the Most Candies?(线段树)

    题目链接:poj 2886 Who Gets the Most Candies? 题目大意:N个人围成一圈玩约瑟夫环游戏,不同的是.步长不固定,由前一个出局的人决定.给定K表示起始的人. 第i个淘汰的 ...

  8. POJ 3159 Candies(差分约束+SPAF)

    题意: 给n个小朋友分发糖果,但小朋友们之间有嫉妒心.接下来m行,每行三个数,分别表示小朋友A希望B得到的糖果不能比他多x个.要求你计算在满足所有小朋友的条件的情况下最多需要准备多少颗糖. 题目: D ...

  9. 1189C. Candies

    C. Candies:题目 思维题,我是笨蛋.我看了半天也没想明白怎么dp,可恶啊. #include <bits/stdc++.h> using namespace std; #defi ...

  10. Give Candies【快速幂+欧拉】

    Give Candies 时间限制: 1 Sec 内存限制: 128 MB 提交: 243 解决: 92 [提交] [状态] [命题人:admin] 题目描述 There are N children ...

最新文章

  1. Allegro 如何把铺好铜皮的平面层互换
  2. Mybatis(三) 映射文件详解
  3. 【数据挖掘】数据挖掘简介
  4. 必须知道的八大种排序算法【java实现】
  5. Apaceh配置httpd-vhosts虚拟主机
  6. [FPGA][DE0] Qsys 加入 FLASH 記憶體 方法及步驟
  7. 阿德莱德大学招聘博士后研究员
  8. 机器人与目标匹配问题及解决 虚拟动力学 纳什平衡 Q-Learning
  9. 期望为线性的选择算法
  10. ArcGIS 查看运行结果
  11. ce标志cad_CAD自定义快捷键+常用符号
  12. 2019hbcpc部分题解
  13. 阿里云商标注册购物车功能怎么用?在哪查看?
  14. Linux(七)DNS域名解析服务器学习
  15. P4556 [Vani有约会]雨天的尾巴(树上的差分+线段树的启发式合并)
  16. 我有一个梦,叫“禾下乘凉梦“!
  17. Thread详解一(interrupt)
  18. mysql 字符串截取查询
  19. 人生重开模拟器(Python实现)
  20. 在web前段,最挣扎的问题尽然是单词!

热门文章

  1. Modbus PLC攻击分析:Smod渗透框架研究
  2. 工控安全| 西门子S7-300攻击分析
  3. linux内核类型lagency,使用u盘安装linux(manjaro)时Grub报错
  4. c语言换行后多空格,关于文件操作,碰到空格就换行
  5. [Gamma阶段]第四次Scrum Meeting
  6. Oracle 存储过程笔记.
  7. Wannafly挑战赛25 A 因子
  8. centos 7 升级python2.7 到3.5
  9. intel 面试总结
  10. Netty自带的心跳机制——IdleStateHandler