C - C
题意:
一罐糖果,里面有n个,有两个人Vasya和Petya,v每天吃k个糖果,p每天吃糖果的10%,求一个最小的k,使v吃掉的糖果数量至少大于n的1/2
题解:
(从网上学习的大佬的思想)
用二分法枚举判断k是否符合条件
#include <bits/stdc++.h>
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
ll n;
ll dt(ll x)
{
ll now;
ll sum;
now=n;
sum=0;
while(now!=0)
{
if(now<=x)
{
sum=sum+now;
break;
}
now=now-x;
sum=sum+x;
now=now-now/10;
}
return sum;
}
int main()
{
ll l,r,m;
cin>>n;
l=1;
r=n;
while(l<r)
{
m=(l+r)/2;
if(dt(m)>=(n+1)/2)
{
r=m;
}
else
{
l=m+1;
}
}
cout<<l<<endl;
}