Give the ratio t (0.5 - > 1) and the initial number of cakes n(1000), then give the size of N cakes (integer, 1e6)
Now you can cut a cake into two pieces of any size
The target state is that the size of the smallest cake is not less than t times the size of the largest cake. How many knives do you need to cut at least?
Data guarantee answers no more than 500
It is an important condition that the number of knives does not exceed 500. I observed that each cake will only be cut into several pieces averagely during the process of making. Then I began to enumerate the minimum cake into several pieces (the maximum is 500). Theoretically, this idea is feasible, but there are too many situations to judge, and I didn't write them out at last
In the formal solution, firstly, the proof of this conclusion is given. If a cake is cut into several pieces unevenly, the situation will be worse than that of the average cut. Secondly, greedy, a 500 cycle, first sweep whether the conditions are met, if not, cut one more piece of the original cake corresponding to the largest cake, Until the conditions are met. The complexity is 1000 * 500. It can be optimized if heap or the like is used
Pay attention to int and double, and make clear whether the numerical value means cutting several copies or cutting several knives
/* LittleFall : Hello! */
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int read();
inline void write(int x);
const int M = 1024;
const double eps = 1e-8;
pair<double,int> save[M];
int main(void)
{
#ifdef _LITTLEFALL_
freopen("in.txt","r",stdin);
#endif
//std::cin.sync_with_stdio(false);
double t;
cin >>t;
int n=read();
for(int i=0;i<n;i++)
save[i].first=read();
int ans;
for(ans=0;ans<=500;ans++)
{
double ma=save[0].first,mi=save[0].first;
int maid=0;
for(int i=1;i<n;i++)
{
if(save[i].first+eps>ma)
ma=save[i].first,maid=i;
if(save[i].first<mi+eps)
mi=save[i].first;
}
if(mi+eps>ma*t) break;
//printf("mi%f ma%f\n",mi,ma );
save[maid].first *= (save[maid].second+1.0)/(save[maid].second+2);
save[maid].second++;
}
printf("%d\n",ans );
return 0;
}
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}