题解:P12642 [KOI 2024 Round 1] 加倍
Solution
我们先把
然后可以将
最后至于 double 的精度问题,我们可以先减去一个较小的数如
AC code
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-6;
long long n,x,s;
double a,b;
int main()
{
cin>>n;
while(n--)
{
cin>>x;
b=log2(x);
if(a>b)
{
x=ceil(a-b-eps);
s+=x;
b+=x;
}
a=b;
}
cout<<s;
return 0;
}