2021.01.30 Rating赛

C - C CodeForces - 991C 

二分查找

#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll n,aa,bb;
bool sec(ll x)
{
ll a=0,b=0,t=n,c=0;
while(t)
{
if(c%2)
{
b+=t/10;
t-=t/10;
}
else
{
if(t>=x)
{
t-=x;
a+=x;
}
else
{
a+=t;
t-=t;
}
}
c++;
}
if(a>=(n+1)/2)return 1;
else return 0;
}
int main()
{
ll l=1,r=1e8+5,ans=0;
cin>>n;
r=n;
while(l<=r)
{
ll mid=l+(r-l)/2;
if(sec(mid))
{
ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
cout<<ans<<endl;
return 0;
}

posted @ 2021-02-07 22:23  SyrupWRLD  阅读(59)  评论(0)    收藏  举报