C. Candies

C. 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 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

( 1n1018

) — 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
Copy
68
Output
Copy
3
Note

In the sample, the amount of candies, with k=3

, would change in the following way (Vasya eats first):

6865595651484441373431282623211817141310966330

.

In total, Vasya would eat 39

candies, while Petya — 29.

思路:

        很明显的二分,10%,每次迭代不超过10次

code:

    

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<array>
#include<queue>
#include<string>
using namespace std;
typedef long long LL;
LL n,ansa,ansb;
bool erfen(LL x)
{
	LL ta=0,tb=0,temp=n,ci=0;
	while (temp)
	{
		if (ci % 2)
		{
			tb += temp / 10;
			temp -= temp / 10;
		}
		else
		{
			if (temp >= x)
			{
				temp -= x;
				ta += x;
			}
			else
			{
				ta += temp;
				temp-= temp;
			}
		}
		ci++;
	}
	if (ta >= (n + 1) / 2)
	{
		return 1;
	}
	else return 0;
}
int main()
{
	LL l = 1, r = 1e8 + 5,ans=0;
	scanf_s("%lld", &n);
	r = n;
	while (l <= r)
	{
		LL mid = l + (r - l) / 2;
		if (erfen(mid))
		{
			ans = mid;
			r = mid-1;
		}
		else
		{
			l=mid+1;
		}
	}
	cout << ans <<endl;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值