CF思维联系– CodeForces - 991C Candies(二分)
ACM思維題訓(xùn)練集合
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.
因?yàn)槭乔笞钚〉?#xff0c;想枚舉,或者倍增,但是枚舉會(huì)超時(shí),倍增需要單調(diào),所以不如直接二分,驗(yàn)證單調(diào)性。
之后可以使用二分,不過(guò)這個(gè)題看完數(shù)據(jù)就只能用log2n的復(fù)雜度過(guò),除了優(yōu)先隊(duì)列,map,set,二分沒(méi)有其他的算法合適,就它了。
然后沒(méi)讀清楚題意,題目說(shuō)的是不小于,大于等于,在二分的時(shí)候沒(méi)有注意check的等號(hào)。
總結(jié)
以上是生活随笔為你收集整理的CF思维联系– CodeForces - 991C Candies(二分)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 纯白机身惊艳!vivo X90“告白”配
- 下一篇: 数学--数论--欧拉降幂和广义欧拉降幂(